我坚持这个问题,当我运行它时,它回来完全错误。 (Pyhon 2.7) [英] Im stuck on this problem and when I run it it comes back completely wrong. (Pyhon 2.7)
问题描述
这是一个问题:
编写一个名为fruit_list.py的shell(基于文本)程序,它创建水果名称列表('Apple','Orange','Banana' ,'Water Melon','Pear')并要求用户从1到5中选择一个数字。然后程序在列表中打印相应的项目。请注意项目编号和列表索引之间的差异。请参阅下面的示例。
示例:
选择1到5之间的数字:3
你有一个香蕉。
PS C:\ Users \ siva \Desktop>
我尝试了什么:
x = ['Apple','Orange','香蕉','西瓜','梨')
y = [1,2,3,4,5]
for x in x:
print x [y]
而y> 5:
print选择1到5之间的数字:
int = raw_input()
This is the question:
Write a shell (text-based) program, called fruit_list.py, that creates the list of fruit names ('Apple', 'Orange', 'Banana', 'Water Melon', 'Pear') and asks the user to pick a number from 1 to 5. The program then prints the corresponding item on the list. Note the difference between the item number and the list index. See the example below.
Example:
Pick a number between 1 and 5: 3
You got a Banana.
PS C:\Users\ssiva\Desktop>
What I have tried:
x = ['Apple', 'Orange', 'Banana', 'Water Melon', 'Pear']
y = [1, 2, 3, 4, 5]
for y in x:
print x[y]
while y > 5:
print "Pick a number between 1 and 5:"
int = raw_input()
推荐答案
x = ['Apple','Orange','Banana','Water Melon','梨')
打印(选择1到5之间的数字:)
密钥>
5或键< 1:
key = raw_input
print x [int(key)]
x = ['Apple', 'Orange', 'Banana', 'Water Melon', 'Pear']
print("Pick a number between 1 and 5:")
while key > "5" or key < "1":
key = raw_input
print x[int(key)]
这篇关于我坚持这个问题,当我运行它时,它回来完全错误。 (Pyhon 2.7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!