Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

something is not working with code moving to the among.py file

+2 votes
asked Apr 1 by Kyzer Maynard (140 points)
I tried to code a story mode type game and when i try to do a file and when i try it it doesnt say an error and just wont print.

https://onlinegdb.com/Orbsc2tAl

1 Answer

0 votes
answered Apr 9 by Peter Minarik (58,190 points)

There are multiple problems with your main.py file.

  1. You should import your other two files to be able to use them.
  2. Your variable b holds a string so comparing it against the numbers 1, 2, 3 will never yields equality. You should store a number in b instead. The simplest solution is to cast the result of your input into an integral number.
  3. Not a problem, but optimization is to compare other values only if the previous comparison was false: use elif.
  4. If you use elif as suggested above, you can tell the user if they entered an invalid choice by adding a final else case.

Your main.py file fixed:

import random
import sys

import among
import fort

a=input("what is your name\n")
b=int(input("hi " + str(a) + " welcome to story mode,\nthe game is your choice,\n1=among us, 2=fortnite, 3=random\n"))
if b == 1:
    among.among()
elif b == 2:
    fort.fort()
elif b == 3:
    d=[1,2]
    e=random.choice(d)
    if e == 1:
        among.among()
    if e == 2:
        fort.fort()
else:
    print("Invalid choice");
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...