Найти - Пользователи
Полная версия: Проблема с программой
Начало » Python для новичков » Проблема с программой
1
GoshkaLP
Всем привет, я новичок на питоне. Вот написал такую программку:
def print_info(object_name, color, price):
print(“Object: ”, object_name)
print(“Color:”, color)
print(“Price:”, price)
while True:
print(“Choose what do u want to do:”)
print(“1.Object_type”)
print(“2.Exit”)
press = input(“>”)
if press == 1:
name = input(“Type the name of the object:”)
cl = input(“Type the color of the object”)
pr = input(“Type the price of the object”)
print_info(name,cl,pr)
else:
break


При запуске ввожу 1, но после этого программа заканчивает свою работу. По сути же дальше я должен был вводить значения для переменных name, cl и pr. Что делать? В чем я допустил ошибку? Я пробовал отдельно прогнать эту функцию, все работает прекрасно. Заранее спасибо за помощь.
GoshkaLP
 def print_info(object_name, color, price):
    print("Object: ", object_name)
    print("Color:", color)
    print("Price:", price)
while True:
    print("Choose what do u want to do:")
    print("1.Object_type")
    print("2.Exit")
    press = input(">")
    if press == 1:
        name = input("Type the name of the object:")
        cl = input("Type the color of the object")
        pr = input("Type the price of the object")
        print_info(name,cl,pr)
    else:
        break
4kpt_IV
 #
press = input(">")
print(type(press))
GoshkaLP
4kpt_IV
Ругается на <class str> , я уже запутался
4kpt_IV
Вы получаете строку и пытаетесь проверить, не является ли она числом да еще и не равна ли 1.

 # 
press = input(">")
    if press == 1:  # никогда не выполнится, так как "1" не равно 1  :(
GoshkaLP
4kpt_IV
Вы получаете строку и пытаетесь проверить, не является ли она числом да еще и не равна ли 1.
пофиксил, тем что 1 взял в кавычки Все равно спасибо
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB