Как я могу заставить этот код печатать то, что мне нужно?

#The program awards team member prizes based on total ticket sales
#Team member total sales and prize awards are printed to the computer screen
#The program terminates when the user does not enter a 'y' or 'Y' to continue

getMoreSales = "y"
teamSales = 0

#Create a while loop to process all of the team members

while getMoreSales == "y":

#Set starting values for program variables

dayOneSales = 0
dayTwoSales = 0
dayThreeSales = 0
memberSales = 0
prizeEarned = " "

#Get sales information

print(" ")
teamMemberName = input("Enter the team member's first name ")
dayOneSales = input("Enter the day 1 ticket sales ")
dayTwoSales = input("Enter the day 2 ticket sales ")
dayThreeSales = input("Enter the day 3 ticket sales ")
memberSales = int(dayOneSales) + int(dayTwoSales) + int(dayThreeSales)
teamSales = (teamSales + memberSales)

#Determine Prize based on total tickets sold


if dayOneSales == 30>0:
print(teamMemberName, "gets a FAST STARTER! button for selling", str(memberSales), "tickets        on the first day!")

if memberSales == 41:
    prizeEarned = 'Team Sweat Shirt!'
elif memberSales == 31:
    prizeEarned = 'Team Tee Shirt!'
elif memberSales == 21:
    prizeEarned = 'Miniature volley ball!'
elif memberSales == 11:
    prizeEarned = 'Plastic mug!'
elif memberSales == 1:
    prizeEarned = 'Cup Holder!'
else:
    prizeEarned = "Team members must sell at least one ticket to get a prize"



print(teamMemberName, " sold ", str(memberSales), " tickets")
if memberSales == 0:
    print("prize awarded is: ", prizeEarned)
else:
    print(prizeEarned)

#Check if program should end

getmoreSales = input("enter y to enter more sales or n to end the program ")

#At the end of the program print total sales for the team

else:
print("The total ticket sales for the team were: ", str(teamSales))

Я должен напечатать, что участник получает БЫСТРЫЙ СТАРТЕР! кнопка продажи (билетов) в первый день, когда участник продает более 30 билетов в первый день.

Всякий раз, когда я запускаю свой код, он просто говорит.

**Введите имя члена команды, Мелани. Введите продажи билетов в первый день 31 Введите продажи билетов на второй день 10 Введите день 3 продажи билетов 5 ** Введите имя члена команды

И просто продолжает идти

getMoreSales != getmoreSales вы назначаете в цикле переменную, отличную от той, которую вы проверяете на условие цикла
Cory Kramer 04.04.2024 20:59

Своими словами, что проверяет dayOneSales == 30>0?

deceze 04.04.2024 21:00

Исправьте отступ показанного кода.

Michael Butscher 04.04.2024 21:02
Почему в Python есть оператор "pass"?
Почему в Python есть оператор "pass"?
Оператор pass в Python - это простая концепция, которую могут быстро освоить даже новички без опыта программирования.
Некоторые методы, о которых вы не знали, что они существуют в Python
Некоторые методы, о которых вы не знали, что они существуют в Python
Python - самый известный и самый простой в изучении язык в наши дни. Имея широкий спектр применения в области машинного обучения, Data Science,...
Основы Python Часть I
Основы Python Часть I
Вы когда-нибудь задумывались, почему в программах на Python вы видите приведенный ниже код?
LeetCode - 1579. Удаление максимального числа ребер для сохранения полной проходимости графа
LeetCode - 1579. Удаление максимального числа ребер для сохранения полной проходимости графа
Алиса и Боб имеют неориентированный граф из n узлов и трех типов ребер:
Оптимизация кода с помощью тернарного оператора Python
Оптимизация кода с помощью тернарного оператора Python
И последнее, что мы хотели бы показать вам, прежде чем двигаться дальше, это
Советы по эффективной веб-разработке с помощью Python
Советы по эффективной веб-разработке с помощью Python
Как веб-разработчик, Python может стать мощным инструментом для создания эффективных и масштабируемых веб-приложений.
3
3
57
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Ответ принят как подходящий

попробуйте поменять if dayOneSales == 30>0 на if dayOneSales >= 30(если включительно 30). Вы неправильно вводите эту строку кода.

Несколько проблем с вашей реализацией:

  1. У вас есть цикл while, и хотя вы предлагаете пользователю выйти из цикла, вы никогда не проверяете этот ответ и не выходите из цикла.

  2. Во всех ваших условиях используется ==, но почти во всех из них должно использоваться неравенство, поскольку вы хотите проверить такие вещи, как «продал ли член команды БОЛЬШЕ 30?»

  3. Для проверки FAST STARTER! button вы используете переменную memberSales в текстовом выводе/печати. Вместо этого вы должны использовать dayOneSales

  4. У вас неправильный отступ, но это может быть просто копирование/вставка.

Вот рабочая версия:

#The program awards team member prizes based on total ticket sales
#Team member total sales and prize awards are printed to the computer screen
#The program terminates when the user does not enter a 'y' or 'Y' to continue

getMoreSales = "y"
teamSales = 0

#Create a while loop to process all of the team members

while getMoreSales == "y":

    #Set starting values for program variables

    dayOneSales = 0
    dayTwoSales = 0
    dayThreeSales = 0
    memberSales = 0
    prizeEarned = " "

    #Get sales information

    print(" ")
    teamMemberName = input("Enter the team member's first name ")
    dayOneSales = int(input("Enter the day 1 ticket sales "))
    dayTwoSales = int(input("Enter the day 2 ticket sales "))
    dayThreeSales = int(input("Enter the day 3 ticket sales "))
    memberSales = int(dayOneSales) + int(dayTwoSales) + int(dayThreeSales)
    teamSales = (teamSales + memberSales)

    #Determine Prize based on total tickets sold


    if dayOneSales >= 30:
        print(teamMemberName, "gets a FAST STARTER! button for selling", str(dayOneSales), "tickets        on the first day!")

    if memberSales >= 41:
        prizeEarned = 'Team Sweat Shirt!'
    elif memberSales >= 31:
        prizeEarned = 'Team Tee Shirt!'
    elif memberSales >= 21:
        prizeEarned = 'Miniature volley ball!'
    elif memberSales >= 11:
        prizeEarned = 'Plastic mug!'
    elif memberSales >= 1:
        prizeEarned = 'Cup Holder!'
    else:
        prizeEarned = "Team members must sell at least one ticket to get a prize"



    print(teamMemberName, " sold ", str(memberSales), " tickets")
    if memberSales > 0:
        print("prize awarded is: ", prizeEarned)
    else:
        print(prizeEarned)

    #Check if program should end
    getmoreSales = input("enter y to enter more sales or n to end the program ")
    if getmoreSales.lower() == 'n': break    

else:
    #At the end of the program print total sales for the team
    print("The total ticket sales for the team were: ", str(teamSales))

Другие вопросы по теме