我该如何修理我的水果机,使符号每次都改变,信用卡只保留小数位?

2024-09-27 09:36:29 发布

您现在位置:Python中文网/ 问答频道 /正文

所以这是一个程序,应该是一个水果机

我遇到的问题是,在第一个之后,同样的符号不断出现,而且信用证变成了一个小数,超过了2位小数

信用证应该与货币相似,所以只允许小数点后两位

`import random

Symbols = ["Cherry", "Bell", "Lemon", "Orange", "Star", "Skull"] #list of available symbols
Credit = (1.00) #set the users start credit to £1
Output1 = []
Output2 = []
Output3 = []
Outputs = [Output1, Output2, Output3]

while Credit >0.00:

    User_Input = input("Would you like a game?")

    if User_Input == "yes":
        Output1.append(random.choice(Symbols))
        Output2.append(random.choice(Symbols))
        Output3.append(random.choice(Symbols))
        Credit = Credit-0.20

        if (Output1 == Output2) or (Output1 == Output3) or (Output2 == Output3): #if 2 of the symbols are the same
            if (Output1 == "Skull" and Output2 == "Skull" and Output3 != "Skull") or (Output1 == "Skull" and Output3 == "Skull" and Output2 != "Skull") or (Output2 == "Skull" and Output3 == "Skull" and Output1 != "Skull"):
            #if 2 of the symbols are skulls and the other is not
            Credit = Credit-1.00 #user loses £1 if two skulls are shown
        Credit = Credit+0.50

    elif (Output1 == Output2) and (Output2 == Output3): #if all symbols match
        if (Output1 == "Bell") and (Output2 == "Bell") and (Output3 == "Bell"): #if all the symbols are bells
            Credit = Credit+5.00 #user earns £5 if 3 bells are shown
        Credit = Credit+1.00

    else: #if symbols are different
        Credit =Credit #if all symbols are different user earns no money

    print ("Your symbols are", Outputs)
    print ("Your Credit now is", Credit)
    Output1 = []
    Output2 = []
    Output3 = []

else: #if the user doesnt type in yes
    Credit = 0.00

if Credit <= 0.00: #when the user doesnt have any credit
    print("End of game Goodbye")`

Tags: andoftheifrandomaresymbolscredit
1条回答
网友
1楼 · 发布于 2024-09-27 09:36:29

除了一个很难遵循的逻辑之外,这个函数的主要问题是变量outputs在函数的开头声明了一次,然后就再也没有了

import random

Symbols = ["Cherry", "Bell", "Lemon", "Orange", "Star", "Skull"] #list of available symbols
Credit = (1.00) #set the users start credit to £1

while Credit >0.00:

User_Input = input("Would you like a game?")

if User_Input == "yes":
    Output1=random.choice(Symbols)
    Output2=random.choice(Symbols)
    Output3=random.choice(Symbols)
    Outputs = [Output1,Output2,Output3]
    Credit-=0.20

    if (Output1 == Output2) or (Output1 == Output3) or (Output2 == Output3): #if 2 of the symbols are the same
        if (Output1 == "Skull" and Output2 == "Skull" and Output3 != "Skull") or (Output1 == "Skull" and Output3 == "Skull" and Output2 != "Skull") or (Output2 == "Skull" and Output3 == "Skull" and Output1 != "Skull"):
        #if 2 of the symbols are skulls and the other is not
        Credit = Credit-1.00 #user loses £1 if two skulls are shown
    Credit = Credit+0.50

elif (Output1 == Output2) and (Output2 == Output3): #if all symbols match
    if (Output1 == "Bell") and (Output2 == "Bell") and (Output3 == "Bell"): #if all the symbols are bells
        Credit = Credit+5.00 #user earns £5 if 3 bells are shown
    Credit = Credit+1.00

else: #if symbols are different
    Credit =Credit #if all symbols are different user earns no money

print ("Your symbols are", Outputs)
print ("Your Credit now is", Credit)

else: #if the user doesnt type in yes
    Credit = 0.00

if Credit <= 0.00: #when the user doesnt have any credit
    print("End of game Goodbye")

相关问题 更多 >

    热门问题