我在Python 3.3.2中制作了这个毕达哥拉斯定理计算器.
我在几行上打印,以便我可以制作一个图表:
print("Welcome to the Pythagoras Theorem Calculator, powered by Python!")
print("Below are the values a, b and c. You will need to input these values after.")
print('''
| .
| .
| .
side a| . side c
| .
| .
|_____________.
side b
''')
Run Code Online (Sandbox Code Playgroud)
如上所示,需要三个撇号而不是语音标记.为什么会这样?这是逃脱角色吗?(我尝试在Google上搜索:http://bit.ly/15a4zes)
我正在编写一个程序,一直要求用户输入名称,直到输入单词END,此时它会打印出名称列表.
代码:
import getpass
import time
import sys
print("Welcome " + getpass.getuser() + "...")
time.sleep(0.25)
print("This program, powered by Python, it will ask you to enter names...")
time.sleep(0.5)
print("...once you have finished, enter END to print off your list")
names = []
for i in names:
name = input("Please enter a name: ")
if name == "END":
print(names)
sys.exit()
names.append(name)
Run Code Online (Sandbox Code Playgroud)
问题是程序在尝试执行for循环之前退出.
为什么会发生这种情况,我该如何解决?
想象一下:
你有一个while循环
你想知道它运行了多少次
你该怎么办???
现在我听到你说,背景是什么?
上下文: 我正在用Python编写这个程序,它考虑的是1到100之间的数字,你要猜测它.猜测参与了一个while循环(请看下面的代码),但我需要知道有多少猜测.
所以,这就是我需要的:
print("It took you " + number_of_guesses + " guesses to get this correct.")
Run Code Online (Sandbox Code Playgroud)
这是Gist的完整代码:https://gist.github.com/anonymous/1d33c9ace3f67642ac09
请记住:我使用的是Python 3x
提前致谢
我正在编写一个程序,不断要求用户输入名称,直到输入单词 END 为止,此时它会以相反的顺序打印出名称列表。
起初,我不知道如何以相反的顺序打印出列表,所以我发现了这个:Travers a list inverse order in Python
我决定使用reversed()内置函数:
import getpass
import time
import sys
print("Welcome " + getpass.getuser() + "...")
time.sleep(0.25)
print("This program, powered by Python, it will ask you to enter names...")
time.sleep(0.5)
print("...once you have finished, enter END to print off your list")
names = []
while True:
name = input("Please enter a name: ")
if name == "END":
print(reversed(names))
sys.exit()
names.append(name)
Run Code Online (Sandbox Code Playgroud)
然而,它打印的只是:
<list_reverseiterator object at 0x0000000002A14F28>
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?我该如何解决这个问题?
非常感谢
我正在尝试制作一个计算气缸体积和表面积的程序; 我目前正在编写它的音量部分.但是,在输出屏幕中,有两位小数.表明:
气缸容积为193019.2896193019.2896cm³
为什么有两个?
之后,我试图让程序询问用户用户想要多少小数位(dp).我怎样才能做到这一点?
这是当前的代码:
print("Welcome to the volume and surface area cylinder calculator powered by Python!")
response = input("To calculate the volume type in 'vol', to calculate the surface area, type in 'SA': ")
if response=="vol" or response =="SA":
pass
else:
print("Please enter a correct statement.")
response = input("To calculate the volume type in 'vol', to calculate the surface area, type in 'SA': ")
if response=="vol":
#Below splits
radius, height = [float(part) for part in input("What is the …Run Code Online (Sandbox Code Playgroud) 我有一个值错误,即使我尝试使用代码,它也不起作用!
我该怎么做对吗? - 我正在使用Python 3.3.2!
这是代码: 
如您所见,该程序会询问您可以行走多少英里,并根据您输入的内容为您提供响应.
这是文本格式的代码:
print("Welcome to Healthometer, powered by Python...")
miles = input("How many miles can you walk?: ")
if float(miles) <= 0:
print("Who do you think you are?!! Go and walk 1000 miles now!")
elif float(miles) >= 10:
print("You are very healthy! Keep it up!")
elif float(miles) > 0 and miles < 10:
print("Good. Try doing 10 miles")
else:
print("Please type in a number!")
miles = float(input("How many miles can you walk?: "))
if miles …Run Code Online (Sandbox Code Playgroud)