Problems with scripts
Wildman
best_lay at yahoo.com
Mon Feb 13 12:54:02 EST 2017
On Mon, 13 Feb 2017 08:30:32 -0800, lauren.sophia1998 wrote:
> Hello! I have 2 python assignments that I just can't figure out. The first one returns the same thing no matter what I input and the second won't accept "done" to stop the program and return answers. Please help!
>
> 1)
> print("How old are you: 17, 18, 19, or 20?")
> answer = input("> ")
> if answer == 17 or 18 or 19 or 20:
> print("Wow, you are old!")
> elif answer != 17 or 18 or 19 or 20:
> if type(answer) is int or float:
> print("You just can't follow drections, can you? Choose either 17, 18, 19, or 20.")
> input("> ")
> elif type(answer) is str:
> print("That isn't even a number. Choose either 17, 18, 19, or 20.")
> input("> ")
Incorrect use of 'or'.
if answer == 17 or answer == 18 or answer == 19 or answer == 20:
elif answer != 17 and answer != 18 and answer != 19 and answer != 20:
if type(answer) is int or type(answer) is float:
> 2)
> print("This program keeps track of the prices of items and how many items bought at that price. Enter 'done' to return the answers.")
> item_num = 1
> total_price = 0
> price = input("What is the price of item number " + str(item_num) + " ? ")
> total_items = 0
> how_many = input("How many items at that price? ")
> while price or how_many != "done":
> total_price = int(total_price) + int(price)
> total_items = int(total_items) + int(how_many)
> item_num = item_num + 1
> price = input("What is the price of item number " + str(item_num) + " ? ")
> how_many = input("How many items at that price? ")
>
> if input == done:
> print("The total price is $" + str(total_price) + ". And the number of items for that price is " + str(total_items) + ".")
Same here:
while price != "done" and how_many != "done":
--
<Wildman> GNU/Linux user #557453
May the Source be with you.
More information about the Python-list
mailing list