【发布时间】:2021-11-02 17:47:23
【问题描述】:
我正在学习 python,但由于某种原因,我得到的输出总是不正确的。不知道我做错了什么或如何解决它,非常感谢任何帮助:
##a. 3 variables —
## The name of a movie
## The number of tickets to purchase
## The total cost of tickets purchased
##
##b. 1 Constant —
## The cost of a single ticket
##2. Create four print statements that will display the values of the variables and the constant along with labels that describe them
##
#Initialize
movieNm = str("")
numTickets = int(0)
totalTicketPrice = float(0.0)
SINGLE_TICKET = int(10)
#input
name = input("Enter the name of the movie you would like to see:")
numTickets = input("Enter the number of tickets you wish to purchase:")
#process
totalTicketPrice = SINGLE_TICKET * numTickets
#output
print("Feature Film", name)
print("Cost of single ticket", SINGLE_TICKET)
print("Number of Tickets purchased", numTickets)
print("Your Total", SINGLE_TICKET * numTickets)
当您测试代码时,输出总是非常错误,我不知道如何修复它。谢谢!
【问题讨论】:
-
str(""),int(0)等完全是多余的。只需""、0等就足以分别初始化一个字符串和一个 int。