对Python用户输入进行排队



我是Python语言的新手,我们的教授给了我们创建队列列表的活动,但我很困惑如何做到这一点。任务是显示用户输入的电影和零食。每次按下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中,变量区分大小写,在最后一部分中,snackSnack重叠,所以请尝试:

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); 

相关内容

  • 没有找到相关文章

最新更新