How to add reset option to a calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to add reset option to a calculator

Need to add reset option by clicking $ sign. How can do it? After that the programme should go to the starting area. https://code.sololearn.com/cOqkietecV4z/?ref=app

27th Jun 2022, 10:55 AM
Jude Maria Bevan
Jude Maria Bevan - avatar
5 Answers
+ 5
Jude Maria Bevan , before using: os.system("clear") we have to import this module: import os
27th Jun 2022, 12:02 PM
Lothar
Lothar - avatar
+ 2
if by reset you mean clearing previous output then you can do it the following way, if choice == "
quot;: os.system("clear") continue (for mac and linux use "clear", for windows use "cls")
27th Jun 2022, 11:06 AM
Abhay
Abhay - avatar
0
It's in python is it okay to put clear
27th Jun 2022, 11:19 AM
Jude Maria Bevan
Jude Maria Bevan - avatar
0
It's comming intendation error after inserting that code https://code.sololearn.com/cqA8nNf60VUQ/?ref=app
27th Jun 2022, 11:29 AM
Jude Maria Bevan
Jude Maria Bevan - avatar
0
My version: from decimal import* d=Decimal def apply(*nums,opp): nums = tuple(map(d,map(float,nums))) res = nums[0] for n in nums[1:]: res = d(eval(f'{res}{opp}{n}')) return str(res) clear = lambda: __import__('os').system('cls' if __import__('os').name!='posix' else 'clear') while True: choice = input(''' • Select Operation: [1] Add: '+' [2] Subtract: '-' [3] Multiply: '*' [4] Divide: '/' [5] Power: '^' [6] Reset: '
#x27; [7] Exit: '#' • Enter the choice: ''') if choice in '+-*/^': nums = input(''' • Enter numbers separated with commas: [:)+> ''').split(',') res = f"{f'{nums[0]}'}{''.join(f'{choice} {i} 'for i in nums[1:])}= {apply(*nums,opp=choice)}" print(res) elif choice=='
#x27;: clear() elif choice=='#': exit('\n• Terminating ... ')
27th Jun 2022, 12:12 PM
Ervis Meta
Ervis Meta - avatar