coding...
-
my stupid-ass python calculator:
from math import squareroot class Result(): def __init__(self, result): self.result = result number_1 = int(input("Enter first number: ")) number_2 = int(input("Enter second number: ")) type = input("Enter operation type: def calculate(no.1, no.2, type): if type == "+": answer = no.1 + no.2 in_log = Result(answer) print(answer) elif type == "-": answer = no.1 - no.2 in_log = Result(answer) print(answer) elif type == "*": answer = no.1 * no.2 in_log = Result(answer) print(answer) elif type == "/": answer = no.1 / no.2 in_log = Result(answer) print(answer) else: print("Please input correct numbers or type.") calculate(number_1, number_2, type) -
my stupid-ass python calculator:
from math import squareroot class Result(): def __init__(self, result): self.result = result number_1 = int(input("Enter first number: ")) number_2 = int(input("Enter second number: ")) type = input("Enter operation type: def calculate(no.1, no.2, type): if type == "+": answer = no.1 + no.2 in_log = Result(answer) print(answer) elif type == "-": answer = no.1 - no.2 in_log = Result(answer) print(answer) elif type == "*": answer = no.1 * no.2 in_log = Result(answer) print(answer) elif type == "/": answer = no.1 / no.2 in_log = Result(answer) print(answer) else: print("Please input correct numbers or type.") calculate(number_1, number_2, type)@danniltrifonov Lol -
@danniltrifonov Lol@KG3M0 said in coding...:
@danniltrifonov Loluser_input = " " if user_input == "Lol": print("suppppp") else: print("Idk") -
@KG3M0 said in coding...:
@danniltrifonov Loluser_input = " " if user_input == "Lol": print("suppppp") else: print("Idk")@danniltrifonov said in [coding\.\.\.](/post/125471):@KG3M0 said in coding...:
@danniltrifonov Loluser_input = " " if user_input == "Lol": print("suppppp") else: print("Idk")Lol!, I Dont Know Much Expect For Spacing Lol `But I'm Trying` That Calculator Is Dead Ass Dumb Tho -
my stupid-ass python calculator:
from math import squareroot class Result(): def __init__(self, result): self.result = result number_1 = int(input("Enter first number: ")) number_2 = int(input("Enter second number: ")) type = input("Enter operation type: def calculate(no.1, no.2, type): if type == "+": answer = no.1 + no.2 in_log = Result(answer) print(answer) elif type == "-": answer = no.1 - no.2 in_log = Result(answer) print(answer) elif type == "*": answer = no.1 * no.2 in_log = Result(answer) print(answer) elif type == "/": answer = no.1 / no.2 in_log = Result(answer) print(answer) else: print("Please input correct numbers or type.") calculate(number_1, number_2, type)@danniltrifonov Looks good! If you use
try...exceptblocks you can make it more error proof (eg. if someone types a string, or a tries to divide by zero)More info: https://www.w3schools.com/python/python_try_except.asp
-
@danniltrifonov Looks good! If you use
try...exceptblocks you can make it more error proof (eg. if someone types a string, or a tries to divide by zero)More info: https://www.w3schools.com/python/python_try_except.asp
@VGMoose
Alright, that makes sense. Then that way the whole app won't crash when someone enters a string like you said. Thank for the tip! -
and also combine the regular occurances of code.. https://www.w3schools.com/python/python_functions.asp
per calculation you could call a function to do the printing etc.. not a massive benefit in this scenario but a good lesson to learn
and also combine the regular occurances of code.. https://www.w3schools.com/python/python_functions.asp
per calculation you could call a function to do the printing etc.. not a massive benefit in this scenario but a good lesson to learn
Yeah that seems like that would help. So your saying create a function that prints the results, and you just pass the values of the calculation into the function? Also thanks for the tip!