Hey I need help on how to divide user inputed numbers

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;
}
2 Likes

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.

1 Like

Oh alright.

1 Like

No, no, you’re right I may have found the wrong profile :smiley:

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.

yes but remember to ping @sonicx180

1 Like

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))
2 Likes

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)}")
2 Likes

Mine and your code should both work.

2 Likes

it works for me sooo

1 Like

hey there for f-strings you don’t need to change the typing :smiley: @Sky

if you notice I edited mine before functionally’s to incorporate this :smiley:

EDIT: did you get the “@” ping @Sky?

2 Likes

Think you pinged the wrong person.

1 Like

oops, does editing it change the ping?

hmmm I didn’t get an @…