how to divide user inputted numbers
Hey @AnthonyPetrillo! Welcome to the community…
Could you please link your repl, or elaborate more, maybe send some screenshots so we can better assistt you?
Thanks!!
The reason is because the numbers you are attempting to divide are not integers or floats. Use this code:
name = int(input("Please enter your name: "))
integer = int(input(name+ ", Please enter an integer: "))
integer2 = int(input(name+ ", Please enter another integer: "))
answer = integer / integer2
if integer % integer2 == 0:
print (f"{integer} is divisble by {integer2}")
else:
print (f"{integer} is NOT divisble by {integer2}")
In what programming language?
In C++
#include <iostream>
int main(){
int one, two, a;
std::cin >> one;
std::cin >> two;
a = one/two;
std::cout << a;
}
Oh, I found a repl on their profile in python and edited their code, I didn’t realize it could be something else XD
smart lol, didn’t think of that.
Oh alright.
No, no, you’re right I may have found the wrong profile
Why is the name an int? Also, you should use mod (%
) to check if it is evenly divisible.
I did not write the code, I merely fixed it to run without errors
Greetings @JaceBillingsley. I looked at your profile and noted that you joined just two days ago. I hope you have a good time in the ol’ community.
It gives me an error when I run it.
It should be this:
name = input("Please enter your name: ")
integer = int(input(name+ ", Please enter an integer: "))
integer2 = int(input(name+ ", Please enter another integer: "))
answer = integer % integer
if answer == 0:
print (str(integer) + " is divisble by " + str(integer2))
else:
print (str(integer) + " is NOT divisble by " + str(integer2))
code:
name = input("Please enter your name: ")
integer = int(input(name + ", Please enter an integer: "))
integer2 = int(input(name + ", Please enter another integer: "))
if integer % integer2 == 0:
print(f"{str(integer)} is divisible by {str(integer2)}")
else:
print(f"{str(integer)} is not divisible by {str(integer2)}")
Mine and your code should both work.
it works for me sooo
hey there for f-strings you don’t need to change the typing @Sky
if you notice I edited mine before functionally’s to incorporate this
EDIT: did you get the “@” ping @Sky?
Think you pinged the wrong person.
oops, does editing it change the ping?
hmmm I didn’t get an @…