-2

I don't think I am using the write syntax to write my code, I am new and would like some help. This code is due tonight so anything would be helpful.

I have tried looking on youtube and other websites, but I couldn't find anything.

print("Hello, I can divide by two! Try me out.")
myNumber = input("What is your number?")
print("myNumber/2")
myAnswer = int(input(myNumber/2))
print("myAnswer")

I expect that the fourth line of code has incorrect syntax for the intended function.

  • `int(myNumber)/2` – Smart Manoj Jun 04 '19 at 05:08
  • Note: you only need `input()` once, not each time you use the number – OneCricketeer Jun 04 '19 at 05:24
  • As SmartManoj pointed out, you are correct in your assumption: line 4 has the issue. I would take a look at the documentation for the [int function](https://docs.python.org/3/library/functions.html#int) for more information as to why SmartManjo's suggested fix works – Jamie Taylor Jun 04 '19 at 05:25

2 Answers2

0

input is always a string. It has to be converted to int for any int operations. Change this.

myNumber = input("What is your number?")

to

myNumber = int(input("What is your number?"))

Praveenkumar
  • 2,056
  • 1
  • 9
  • 18
0

You are taking input and storing it in myNumber which is string type. you can type-cast the myNumber to integer or float data type before dividing it by two.

print("Hello, I can divide by two! Try me out.")
myNumber = input("What is your number?")
print("myNumber/2")
myAnswer = int(myNumber)/2
print("myAnswer is ",myAnswer)

I believe this will do your work.

Yash singh Bishen
  • 469
  • 1
  • 5
  • 6