coding...
-
my stupid-[censored] 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-[censored] 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 [censored] Dumb Tho -
my stupid-[censored] 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
-
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
-
@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!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login