def Use_Last_Answer():
choose_opt = input('''Do you want to use the previous answer? (Y/N)''' )
if choose_opt.upper() == 'Y': #Function for ANS
x = ANS
find_fractions_2
elif choose_opt.upper() == 'N':
find_fractions()
else:
Use_Last_Answer()
def find_fractions():
x = 0 # makes x reset but not necessary
x = Fraction(input('''Enter (1st) fraction:'''))
find_fractions_2()
def find_fractions_2():
operation = input('''
What do you want to do?
Add (1) (e.g) 1/5 + 1/10 = 3/10
Enter Function number:''')
if(operation != '1'):
print("You must enter a valid operation")
else:
y = Fraction(input('''Enter (2nd) fraction:'''))
if operation == '1':
print('''Adding Fractions...''')
print('{} + {} = '.format(x, y))
ANS = print(x + y)
Use_Last_Answer()
find_fractions()
(这不是整个代码,只是为了适合而削减(。
我正在尝试制作一个通常在计算器上可用的 ANS 函数,方法是从前面的等式中制作 ANS = (x+y)
<- 并制作一个 def 以查看 ANS 是否能够成为 x 变量。我def find_functions()
分成两部分以绕过x = Fraction(input('''Enter (1st) fraction:'''))
并转到哪个操作(例如(加、减等,使前一个答案成为新方程 x 变量。
但是它不起作用,当我def find_fractions()
分成两部分并开始一个新方程时,x 变量不会传递到第二部分,并且 x+y 不会计算。我在高中,这是我计算机科学的第5周,所以我不会知道太多的行话。
一般来说,如果你想保存一些东西并在以后使用它,你会需要一个"全局"变量。 这些位于脚本的开头,任何函数都可以使用它或更改它。
ans = 0
def this_changes_ans():
ans += 0.75
def use_previous():
If input == "Y":
ans = ans
else:
ans = 0
也。。
Ans = print(x + y)
只。。。不