python编程从入门到实践 课后习题

2025-03-22 12:28:31
推荐回答(5个)
回答1:

# -- coding: utf-8 --
# 电影票
prompt = "\nThis theater charge different fees according to different ages."
prompt += "\nEnter your age, press 'quit' to exit the program! :"

age = input(prompt)
age = int(age)
# 1.条件测试
while age >= 0:
    if age < 3:
        print("Your age is " + str(age) + ", and your charge is free." + "\n")
    elif (age >= 3) and (age < 12):
        print("Your age is " + str(age) + ", and your charge is 10." + "\n")
    else:
        print("Your age is " + str(age) + ", and your charge is 15." + "\n")
    age -= 1

你好啊!我最近也在研究python。我在用条件测试时,为了终止循环用了自减运算符,但是这样编写是有问题的。可以一起讨论头论啊

回答2:

都是一个意思!核心编程也是基础编程基础编程还是基础编程无非就是python中各种对象类型的用法,线程进程以及常用的模块的用法介绍!都可以,新手的话,我建议哪个都别买,看手册或者廖大神的手册!!!

回答3:

age = ''
while age != 0:
age = input('请问您的小孩儿几岁了:')
if int(age) == 0:
break
elif int(age) > 0 and int(age) < 3:
print('免费')
break
elif int(age) >= 3 and int(age) < 12:
print('票价是10元')
break
elif int(age) >= 12:
print('票价是15元')
break

回答4:

prompt="\nPlease enter your age: "
prompt += "\n(enter 8888' when you are finished.)"
active = True
while active :

age = input(prompt)

age = int(age)

if age == 8888:
active = False

if age < 3:
print ("票价免费")

elif age < 12:
print("票价10美元")

else:
print("票价15美元")

回答5: