我正在使用2.3 IDLE而且我遇到了问题.
我需要检查一个数字是否介于两个其他数字10000和30000之间:
if number >= 10000 and number >= 30000:
print ("you have to pay 5% taxes")
Run Code Online (Sandbox Code Playgroud)
它运作得不好.
I'm using python 3.2.3 IDLE and this is my code:
originalList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, …Run Code Online (Sandbox Code Playgroud) 这里是python的新手.我正在尝试编写一个程序来计算句子中的平均单词长度,我必须使用.split命令来完成.顺便说一句我使用python 3.2
这是我到目前为止所写的内容
sentence = input("Please enter a sentence: ")
print(sentence.split())
Run Code Online (Sandbox Code Playgroud)
到目前为止,我让用户输入一个句子并成功地分割他们输入的每个单词,例如:您好我的名字是Bob,它将其分为['hi','my','name','is','鲍勃']
但现在我迷失了,我不知道如何计算每个单词并找到句子的平均长度.
可能重复:
如何在Python中获取用户输入的列表?
我目前有这个:
c = eval(input("Enter a group of numbers "))
#say someone types 123
print (c)
#prints out 123
Run Code Online (Sandbox Code Playgroud)
我要这个:
c = eval(input("Enter a group of numbers "))
#say they enter 123
print (c)
#prints out [1,2,3]
Run Code Online (Sandbox Code Playgroud)
我想123最终成为[1,2,3].我怎样才能做到这一点?
这是我的代码:
def Area():
area = pi * radius * radius
pi = 3.14
radius = diameter * 2
def cost():
diameter = eval(input("diamater: "))
print ("Area is", area)
cost()
Run Code Online (Sandbox Code Playgroud)
它说区域没有定义,但我有一个名为area的变量!
这是我在python 3.2.3上的代码IDLE:
numbers = []
numbers = input("(Enter a empty string to quit) Enter a number: ")
while numbers != "":
numbers = input("(Enter a empty string to quit) Enter a number; ")
numbers.append(n)
print ("The list is", numbers)
Run Code Online (Sandbox Code Playgroud)
现在的问题是,我无法追加清单.如果我使数字= int(输入(然后它适用于附加列表,但不会让我退出输入数字.如果我使数字=输入像我现在一样,它不会让我附加列表
我怎样才能将这些数字附加到列表中?
这是我的代码:
total = int(input("How many students are there "))
print("Please enter their scores, between 1 - 100")
myList = []
for i in range (total):
n = int(input("Enter a test score >> "))
myList.append(n)
Run Code Online (Sandbox Code Playgroud)
基本上我正在编写一个计算测试分数的程序,但首先用户必须输入0到100之间的分数.
如果用户输入超出该范围的测试分数,我希望程序告诉用户重写该数字.我不希望程序以错误结束.我怎样才能做到这一点?
我正在使用python 3.2.3空闲这是我的代码:
number = input("please enter 1 or 2")
if number != 1 or 2: #this part is wrong
print("You didn't enter 1 or 2")
Run Code Online (Sandbox Code Playgroud)
我的代码不正确。我想这样做,以便如果用户未输入1或2,则会弹出错误。说他们输入1.5、3等,不是1.0或2.0。
我该如何使用!=命令?
我正在尝试运行一个1 + 1/3 + 1/5 - 1/7 + 1/9的循环......等等
但它一直是1!
我试过了
double answer = 1 + 1/3 + 1/5 - 1/7 + 1/9 - 1/11;
displays 1
Run Code Online (Sandbox Code Playgroud)
数学很奇怪,就像我甚至搞砸了一样
double answer = 1 / 5; //should display 0.2
displays 0!!!!!!!!
Run Code Online (Sandbox Code Playgroud)