队列 Python 用户输入
Queue Python User Input
我是 Python 语言的新手,我们的教授给了我们 activity 关于创建队列列表的知识,但我很困惑如何去做。任务是显示用户输入的电影和零食。每次按 S 时,零食都会被移除。我希望有人能解释为什么会发生这种情况以及我应该添加什么。非常感谢。
Movies = [];
movie = str (input ("Enter a movie 1 of 3: "));
Movies.append(movie)
movie = str (input ("Enter a movie 2 of 3: "));
Movies.append(movie)
movie = str (input ("Enter a movie 3 of 3: "));
Movies.append(movie)
Snack = [];
snack = str (input ("Enter snack 1 of 3: "));
Snack.append(snack)
snack = str (input ("Enter snack 2 of 3: "));
Snack.append(snack)
snack = str (input ("Enter snack 3 of 3: "));
Snack.append(snack)
print("Movies to watch are ", Movies);
print("Snacks available are ", snack);
print("Press S each time you finish a snack.");
eat = input();
if str.lower(eat)== "s":
print (snack.pop());
print (snack);
Output:
Enter a movie 1 of 3: Avengers
Enter a movie 2 of 3: Forrest Gump
Enter a movie 3 of 3: Lucy
Enter snack 1 of 3: Milktea
Enter snack 2 of 3: Pizza
Enter snack 3 of 3: Fries
Movies to watch are ['Avengers', 'Forrest Gump', 'Lucy']
Snacks available are fries #this is my problem
Press S each time you finish a snack.
S
在 python 中变量是 case-sensitive,在最后一部分你重叠了 snack
和 Snack
所以尝试:
print("Movies to watch are ", Movies);
print("Snacks available are ", Snack);
print("Press S each time you finish a snack.");
eat = input();
if str.lower(eat)== "s":
print (Snack.pop());
print (Snack);
我是 Python 语言的新手,我们的教授给了我们 activity 关于创建队列列表的知识,但我很困惑如何去做。任务是显示用户输入的电影和零食。每次按 S 时,零食都会被移除。我希望有人能解释为什么会发生这种情况以及我应该添加什么。非常感谢。
Movies = [];
movie = str (input ("Enter a movie 1 of 3: "));
Movies.append(movie)
movie = str (input ("Enter a movie 2 of 3: "));
Movies.append(movie)
movie = str (input ("Enter a movie 3 of 3: "));
Movies.append(movie)
Snack = [];
snack = str (input ("Enter snack 1 of 3: "));
Snack.append(snack)
snack = str (input ("Enter snack 2 of 3: "));
Snack.append(snack)
snack = str (input ("Enter snack 3 of 3: "));
Snack.append(snack)
print("Movies to watch are ", Movies);
print("Snacks available are ", snack);
print("Press S each time you finish a snack.");
eat = input();
if str.lower(eat)== "s":
print (snack.pop());
print (snack);
Output:
Enter a movie 1 of 3: Avengers
Enter a movie 2 of 3: Forrest Gump
Enter a movie 3 of 3: Lucy
Enter snack 1 of 3: Milktea
Enter snack 2 of 3: Pizza
Enter snack 3 of 3: Fries
Movies to watch are ['Avengers', 'Forrest Gump', 'Lucy']
Snacks available are fries #this is my problem
Press S each time you finish a snack.
S
在 python 中变量是 case-sensitive,在最后一部分你重叠了 snack
和 Snack
所以尝试:
print("Movies to watch are ", Movies);
print("Snacks available are ", Snack);
print("Press S each time you finish a snack.");
eat = input();
if str.lower(eat)== "s":
print (Snack.pop());
print (Snack);