Jul-14-2022, 12:40 PM
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.
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