我在python中创建一个程序,我已经完成了它,在shell中运行它并且它工作得很好。但是,当我在交互式窗口中运行程序时,它会在空闲窗口中产生错误,但它不会。
窗口崩溃前的错误图片:
### COFFEE SHOP APP ###
# IMPORTS
from Motto import ourMotto
import time
import os
import sys
# MAIN CODE
def CoffeeShopApp():
# VARIABLES
orderCost = 0
smallCost = 2.00
mediumCost = 3.50
largeCost = 4.75
spicyCost = 5.25
coffeeInput = False
sugarCost = 0.05
sugarInput = False
syrupCost = 0.50
syrupInput = False
print("Welcome to the Michael the Moose Coffee App - Where the price is right")
print("You've tried BartSucks, and it sucks so now try the best")
print("We will guide you through the ordering process and our amazing Barista 'Michelle' in Barcelona will then serve you\n")
print("And our amazing Barista 'Michelle' in Barcelona will then serve you\n")
while coffeeInput == False:
tempSize = input(
"""
What size would you like your coffee?
Small - 2€, Medium - 3.50€, Large - 4.75€ or Spicy - 5.25€
"""
)
tempSize = tempSize.title()
if tempSize == "Small":
coffeeSize = "Small"
coffeeInput = True
orderCost = (orderCost + smallCost)
elif tempSize == "Medium":
coffeeSize = "Medium"
coffeeInput = True
orderCost = (orderCost + mediumCost)
elif tempSize == "Large":
coffeeSize = "Large"
coffeeInput = True
orderCost = (orderCost + largeCost)
elif tempSize == "Spicy":
coffeeSize = "Spicy"
coffeeInput = True
orderCost = (orderCost + spicyCost)
else:
print("Please enter a valid size")
coffeeInput = False
time.sleep(0.5)
print()
orderCost = str(orderCost)
print("Ok, currently your order costs "+orderCost+"€")
time.sleep(0.5)
print()
while sugarInput == False:
tempSugar = int(input(
"""
How many sugars would you like added to your coffee?
1 sugar - 0.05€, 2 sugars - 0.10€, 3 sugars - 0.15€, 4 sugars - 0.20€:
"""
))
if isinstance(tempSugar, int):
if tempSugar > 4:
print("Please enter a valid number of sugars")
sugarInput = False
time.sleep(0.5)
else:
orderCost = float(orderCost)
orderCost = (orderCost + (tempSugar * sugarCost))
sugarInput = True
else:
print("Please enter a number")
print()
orderCost=str(orderCost)
print("Ok, currently your order costs "+orderCost+"€")
time.sleep(0.5)
print()
while syrupInput == False:
tempSyrup = input(
"""
Would you like syrup? (0.50€):
""")
tempSyrup = tempSyrup.title()
if tempSyrup == "Yes":
syrupInput = True
elif tempSyrup == "No":
syrupInput = True
else:
print("Please enter either yes/no")
time.sleep(0.5)
orderCost = str(orderCost)
print("Alright, your final order cost comes up to: "+orderCost+"€")
name = input("Please enter your name and our barista Michelle will get straight to work on your coffee: ")
name = name.upper()
tempSugar = str(tempSugar)
orderCost = str(orderCost)
lines = ['Here is your new order: It is size: '+tempSize+'',
'There are '+tempSugar+' sugars to be put in the coffee',
'and they have said '+tempSyrup+' to having syrup.',
'Their name is '+name+,
'It will cost: '+orderCost+'€',
'',
'',
'',
'',
'',
'',
'',
ourMotto]
with open('MichelleMooseCoffeeOrders.txt', 'w') as MMC:
for l in lines:
MMC.write(l + '\n')
MMC.close()
print(
"""
Your order has been proccessed
Please come and collect your order at the shop within the hour,
or your order will be incinerated
"""
)
input("Press ENTER to exit the app")
if mode == 'Interactive' or mode == 'I':
os.system('cls')
mode = input("Are you in shell/interactive mode?")
mode = mode.title()
if mode == 'Interactive' or mode == 'I':
os.system('cls')
input("Slide left to sign in")
if mode == 'Interactive' or mode == 'I':
os.system('cls')
appreal = False
while appreal == False:
app = input(
"""
What app would you like to use?
Coffee Shop, (more coming sometime soon)
"""
)
app = app.title()
if app == 'Coffee Shop' or app == 'Cs':
if mode == 'Interactive' or mode == 'I':
os.system('cls')
CoffeeShopApp()
elif app == '':
pass
第169行是对子程序的调用
第30行是这样形状的印刷品的一端:
print(
"""
*text here*
"""
)
第12行似乎是指python文件中的一个程序。 在程序中,它从与此问题相同的位置从python程序导入变量。
导入的文件是:
ourMotto = ('You have been playing for over an hour. Please do not forget to take a break.')
它写入名为:
的同一文件位置中的文本文件MichelleMooseCoffeeOrders
如果您需要我添加有关该计划的更多信息或帮我格式化此问题,请发表评论。 (我是堆叠溢出的新手,我还在学习如何格式化问题以便反馈有帮助)
utf-8编码后的错误代码:
Traceback (most recent call last):
File"Z:\Year9\LessonWork\I.C.T\ComputerScience(Wednesday)\Programming\CoffeeShopApp\CoffeeShopApp.p, line 169, in <module>
CoffeeShopApp
File"Z:\Year9\LessonWork\I.C.T\ComputerScience(Wednesday)\Programming\CoffeeShopApp\CoffeeShopApp.py", line 30, in CoffeeShopApp
"""
File "C:\Program Files (x86)\Python35-32\lib\encoding\cp850.py", line 12, in encode
return codecs.charmaps_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in position 76:P character maps to <undefined>