Im trying to make a game director in python, but failing miserably as when i try to open the second program, it does in the order, so first 1, then 2, etc here is a part of my code:
*import os
print('What game do you want to play?')
print('1. Hangman')
print('2. Dragon Realm')
print('3. Crafting Challenge')
gamechoice = input()
if gamechoice == '1':
print('Ok, sending you there...')
os.startfile('hangman.py')
gamechoice = input()
if gamechoice == '2':
print('Ok, sending you there...')
os.startfile('Dragon Realm.py')
gamechoice = input()
if gamechoice == '3':
print('Ok, sending you there...')
os.startfile('crafting challenge.py')*
You only need to get the input once. And in the if-statements you need to indent properly so you don't execute code that you didn't mean too.
Something like this might work:
import os
print('What game do you want to play?')
print('1. Hangman')
print('2. Dragon Realm')
print('3. Crafting Challenge')
gamechoice = input()
print('Ok, sending you there...')
if gamechoice == 1:
os.startfile('hangman.py')
elif gamechoice == 2:
os.startfile('Dragon Realm.py')
elif gamechoice == 3:
os.startfile('crafting challenge.py')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments