我要制造一台假电视。
挑战在于
编写一个模拟电视的程序,将其创建为
对象。用户应该能够输入频道编号和
提高或降低音量。确保通道号
音量保持在有效范围内。
我一直收到一个错误我现在的代码是
class Television(object):
"""fake tv"""
def tv(volume = 0,chanel = 0):
tv.volume = vol
tv.chanel = chan
def volu(volume):
if vol > 100:
print('That volumes too high')
else:
return vol
def channel(chanel):
if chanel > 64:
print('THat channel doesnt exist')
def main():
choice = None
while choice != "0":
print \
("""
YO TV
0 - Turn off tv
1 - Tv status
2 - Change channel
3 - Change volume
""")
choice = input("Choice: ")
print()
# exit
if choice == "0":
print("Good-bye.")
# tv status
elif choice == "1":
print('The volume is ',tv.volume, 'The channel is ', tv.chanel)
# channel control
elif choice == "2":
chanchange= int(input('What channel do you want to watch'))
tv.channel()
print(chan,' is the channel')
# volume control
elif choice == "3":
volchange= int(input('What would you like the volume to be'))
tv.channel
print(vol,' is the volume level')
# some unknown choice
else:
print("\nSorry, but", choice, "isn't a valid choice.")
main()
("\n\nPress the enter key to exit.")
下面是一个示例,其中的注释指出了一些问题:
或使用属性:
^{pr2}$相关问题 更多 >
编程相关推荐