-1

Can someone explain to me, in plain english whats going on in this line

hourly_wage = int(input('Enter hourly wage: '))

From what I understand integers allow you to multiply,add and divide. If I were to say fruit = apples + 10 and I didn't have an integer function to call that out there would be an error.

I am just trying to grasp the next step of that. I may be wrong in the above explanation, if I am please correct me. Thank you for your help.

Tom Karzes
  • 22,815
  • 2
  • 22
  • 41
  • All this does is prompt the user for input (with `Enter hourly wage:`), convert the test entered by the user into an integer, and assign the result to `hourly_wage`. – Tom Karzes Apr 03 '21 at 00:51
  • Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – Tom Karzes Apr 03 '21 at 00:52
  • @TomKarzes Would also be good to mention that it's going to throw a nice error if the input contains anything other than numbers and a space. – Kaleba KB Keitshokile Apr 03 '21 at 01:07

2 Answers2

1

in Python, all input is returned as a string.

input('Enter hourly wage: '))

this is just accepting the user input. so if the user were to enter the number 100 and you were to print out its type, Python would return string.

int(input('Enter hourly wage: '))

this is doing the same as above but it's forcing the input to be an integer instead.

hourly_wage = int(input('Enter hourly wage: '))

now we take the integer value and store it in hourly_wage

Marc Karam
  • 445
  • 6
  • 22
0

My Python understanding is minimal, but from what I can understand that line is simply defining that an input from the user in the "Enter hourly wage" field of some application, etc is an integer and that it equals hourly_wage. Another way to say that is hourly_wage = the integer the user typed

If anyone has further/better knowledge of this please do correct me.

Zediious
  • 1
  • 2