简体   繁体   English

这是我的计算机项目,我遇到错误,我不知道如何修复

[英]This is my Computer project and i am getting error and i don't know how to fix

#this t_movie function is used to select movie name

def t_movie():
   global f
    f = f+1
    print("which movie do you want to watch?")
    print("1,movie 1 ")
    print("2,movie 2 ")
    print("3,movie 3")
    print("4,back")
    movie = int(input("choose your movie: "))
    if movie == 4:
#in this it goes to center function and from center it goes to movie function and it comes back here and then go to theater
      center()
      theater()
      return 0
    if f == 1:
      theater()

# this theater function used to select screen
def theater():
    print("which screen do you want to watch movie: ")
    print("1,SCREEN 1")
    print("2,SCREEN 2")
    print("3,SCREEN 3")
    a = int(input("choose your screen: "))
    ticket = int(input("number of ticket do you want?: "))
    timing(a)

# this timing function used to select timing for movie

def timing(a):
    time1 = {
        "1": "10.00-1.00",
        "2": "1.10-4.10",
        "3": "4.20-7.20",
        "4": "7.30-10.30"
    }

    time2 = {
        "1": "10.15-1.15",
        "2": "1.25-4.25",
        "3": "4.35-7.35",
        "4": "7.45-10.45"
    }

    time3 = {
        "1": "10.30-1.30",
        "2": "1.40-4.40",
        "3": "4.50-7.50",
        "4": "8.00-10.45"
    }

    if a == 1:
        print("choose your time:")
        print(time1)
        t = input("select your time:")
        x = time1[t]
        print("successful!, enjoy movie at "+x)
    elif a == 2:
        print("choose your time:")
        print(time2)
        t = input("select your time:")
        x = time2[t]
        print("successful!, enjoy movie at "+x)
    elif a == 3:
        print("choose your time:")
        print(time3)
        t = input("select your time:")
        x = time3[t]
        print("successful!, enjoy movie at "+x)
    return 0

def movie(theater):
    if theater == 1:
        t_movie()
    elif theater == 2:
        t_movie()
    elif theater == 3:
        t_movie()
    elif theater == 4:
        city()
    else:
        print("wrong choice")

def center():
    print("which theater do you wish to see movie? ")
    print("1,Inox")
    print("2,Icon")
    print("3,pvp")
    print("4,back")
    a = int(input("choose your option: "))
    movie(a)
    return 0

# this function is used to select city

def city():
    print("Hi welcome to movie ticket booking: ")
    print("where you want to watch movie?:")
    print("1,city 1")
    print("2,city 2 ")
    print("3,city 3 ")
    place = int(input("choose your option: "))
    if place == 1:
      center()
    elif place == 2:
      center()
    elif place == 3:
      center()
    else:
      print("wrong choice")

city() # it calls the function city

Please any one just point out Mistake i can't find it请任何人指出我找不到的错误

Since you declared the variable f in the function t_movie , the f will not be available outside the function t_movie .由于您在函数 t_movie 中声明了变量f ,因此f在函数t_movie之外将不可t_movie That means the f will only be defined whenever the function t_movie is invoked, after processing through the t_movie , the f variable will be deleted.这意味着f只会在调用函数t_movie时定义,在通过t_movie处理后, f变量将被删除。

Solution : In order to make the f variable available for all of the functions, consider declaring it outside of the method (the same level as the invoked main method, in your case, it's city() )解决方案:为了使f变量可用于所有函数,请考虑在方法外部声明它(与调用的 main 方法处于同一级别,在您的情况下,它是city()

I have put f = 0 outside the function and it's work and give one space to global.我把 f = 0 放在函数外面,它起作用了,给全局留了一个空间。 Global was not perfect in function. Global 在功能上并不完美。

#this t_movie function is used to select movie name #这个t_movie函数是用来选择电影名称的

f = 0

def t_movie():
    global f 
    f = f+1
    print("which movie do you want to watch?")
    print("1,movie 1 ")
    print("2,movie 2 ")
    print("3,movie 3")
    print("4,back")
    movie = int(input("choose your movie: "))
    if movie == 4:
#in this it goes to center function and from center it goes to movie function and it comes back here and then go to theater
      center()
      theater()
      return 0
    if f == 1:
      theater()

# this theater function used to select screen
def theater():
    print("which screen do you want to watch movie: ")
    print("1,SCREEN 1")
    print("2,SCREEN 2")
    print("3,SCREEN 3")
    a = int(input("choose your screen: "))
    ticket = int(input("number of ticket do you want?: "))
    timing(a)

# this timing function used to select timing for movie

def timing(a):
    time1 = {
        "1": "10.00-1.00",
        "2": "1.10-4.10",
        "3": "4.20-7.20",
        "4": "7.30-10.30"
    }

    time2 = {
        "1": "10.15-1.15",
        "2": "1.25-4.25",
        "3": "4.35-7.35",
        "4": "7.45-10.45"
    }

    time3 = {
        "1": "10.30-1.30",
        "2": "1.40-4.40",
        "3": "4.50-7.50",
        "4": "8.00-10.45"
    }

    if a == 1:
        print("choose your time:")
        print(time1)
        t = input("select your time:")
        x = time1[t]
        print("successful!, enjoy movie at "+x)
    elif a == 2:
        print("choose your time:")
        print(time2)
        t = input("select your time:")
        x = time2[t]
        print("successful!, enjoy movie at "+x)
    elif a == 3:
        print("choose your time:")
        print(time3)
        t = input("select your time:")
        x = time3[t]
        print("successful!, enjoy movie at "+x)
    return 0

def movie(theater):
    if theater == 1:
        t_movie()
    elif theater == 2:
        t_movie()
    elif theater == 3:
        t_movie()
    elif theater == 4:
        city()
    else:
        print("wrong choice")

def center():
    print("which theater do you wish to see movie? ")
    print("1,Inox")
    print("2,Icon")
    print("3,pvp")
    print("4,back")
    a = int(input("choose your option: "))
    movie(a)
    return 0

# this function is used to select city

def city():
    print("Hi welcome to movie ticket booking: ")
    print("where you want to watch movie?:")
    print("1,city 1")
    print("2,city 2 ")
    print("3,city 3 ")
    place = int(input("choose your option: "))
    if place == 1:
      center()
    elif place == 2:
      center()
    elif place == 3:
      center()
    else:
      print("wrong choice")

city() # it calls the function city

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到EOF错误,不知道如何解决 - I am getting an EOF error and don't know how to fix it 我在我的 pythonanywhere 中收到 ImportError,我不知道它是什么或如何修复它 - I am getting an ImportError in my pythonanywhere and I don't know what it is or how to fix it Python:我的代码出错,我不知道如何修复它 - Python: Error in my code and i don't know how to fix it 不知道为什么我收到 StopIteration 错误 - Don't know why I am getting StopIteration error 我不知道如何修复一元 +: 'str' 错误 - I don't know how to fix an unary +: 'str' error 我的代码正在使用递归产生逻辑错误,但我不知道如何解决 - My code is producing a logic error with recursion and I don't know how to fix it Django / JQuery语法错误:我不知道为什么收到此错误 - Django/JQuery Syntax Error: I don't know why I am getting this error 我不知道为什么我收到错误:NameError: name 'changeRate' is not defined - I don't know why I am getting the error: NameError: name 'changeRate' is not defined 我在做项目时遇到了 EOFError,我不知道如何修复它 - I got An EOFError while doing a project and I don't know how to fix it 我写了这段代码,但我的 output 不是应有的二维,我不知道如何修复它 - I wrote this code but my output is not in 2D as it should have been, and I don't know how to fix it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM