Python Forum
If 2nd input in the game is correct, replace with 1st input and loop the game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If 2nd input in the game is correct, replace with 1st input and loop the game
#1
Trying to write a simple game to improve my Python knowledge as a newbie.

The game starts with asking a first country name Then asking another country name starts with the end letter of first one. If correct, assign second data as first and loop the game till wrong answer or user wants to quit.

The question is: how to assign the 2nd data as the 1st data and loop the game? Below code does not run as I want. Doesnt matter if 2nd input is correct or not, it just prints 'you lost!' and exits.

first_data=input('enter a country name: ')
print(first_data)
last_letter=str(first_data[-1])
print(last_letter)
second_data=input('enter a country name starts with the last letter of previous country name: ')

while last_letter==second_data[0]:
    #this is where I want to add the loop. If correct, then use the second data as first one and re-run the code from beginning
    second_data=first_data
    print(first_data)

print('you lost!')
Output:
enter a country name: nigeria nigeria a enter a country name starts with the last letter of previous country name: albania nigeria you lost! Process finished with exit code 0
Reply


Messages In This Thread
If 2nd input in the game is correct, replace with 1st input and loop the game - by tylerdurdane - Jul-14-2022, 12:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Game - Choice Based theor 4 3,125 May-22-2024, 01:17 PM
Last Post: alanbriggs
  My first python game : Tic-Tac-Toe ForsakenDusk 5 299 May-21-2024, 03:24 AM
Last Post: deanhystad
  [PyGame] adding mouse control to game flash77 7 616 May-21-2024, 01:05 AM
Last Post: XavierPlatinum
  get a game to run in full screen mode agencyclearly 1 442 May-12-2024, 11:23 AM
Last Post: menator01
  Game "Fluppy bird" nastia_nadashkevich 1 428 Apr-19-2024, 08:45 PM
Last Post: deanhystad
  [PyGame] Waiting screen until user input - PiBooth world90 2 1,177 Apr-19-2024, 03:34 AM
Last Post: attractalderman
  Isometric game pygame Tiled howardberger 1 826 Jan-31-2024, 10:01 PM
Last Post: deanhystad
  I want to add a bullet function to my game. how would i go about it? Iyjja 5 1,199 Jan-09-2024, 05:42 PM
Last Post: Iyjja
  GPS Points to map for game/simulator AvgPlum 1 2,062 Jun-22-2023, 06:38 PM
Last Post: marynetherton
  [PyGame] When I hit the space bar from the home screen, it sends me to the game over screen JesusisKing 1 1,123 Apr-30-2023, 10:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020