-3

Hello i am making a MPH converter to KPH the only thing I need help with is how you store digits. Basically I want to be able to write in a random digit for example 170 mph and then it will store the digit and then later convert it kph. I have tried searching it up but I can't find any thing that helps me

edit: I am very sorry wasting everybody's time I had no idea that the documents existed so again I'm am very sorry I'm just a beginner hope you understand

print("Type in the Mph speed")
input()
Wixnm
  • 7
  • 2
  • 3
    This is the most basic usage of `input()`. Did you read the [documentation?](https://docs.python.org/3/library/functions.html#input) What do you find is unclear? `input()` returns a string. You need to convert it to an integer or a float to use it as a numeric quantity. – Pranav Hosangadi Nov 24 '20 at 18:06
  • You need to store your value in a variable x = input(“Type in the Mph speed”) – Zach Nov 24 '20 at 18:07
  • 1
    Duplicate: https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers Please don't ask a new question on Stack Overflow when a search would suffice. [How much research effort is expected of Stack Overflow users?](//meta.stackoverflow.com/a/261593/843953) – Pranav Hosangadi Nov 24 '20 at 18:08
  • 1
    Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – Ayush Garg Nov 24 '20 at 18:12

2 Answers2

-1

You can store things in variables - the input function returns what the user typed in as a string, so you have to use an int to convert it into a number:

print("Type in the Mph speed")
speed = int(input())

You can also simplify this by putting the string in the input function:

speed = int(input("Type in the Mph speed: ")) # This will print on the same line as the user input, hence the colon and space to make it more readable

This is a very basic question, though, so I would suggest looking at a python tutorial/the docs.

Ayush Garg
  • 2,234
  • 2
  • 12
  • 28
-1

This is done by input function a = Input ("enter your number: ") What this line does is that.. It displays " Enter your number: " On the output screen and request you to give any input and store that input to the variable 'a' here. But in input function.. By default.. Always a character type is going stored. Here in the above code.. If you type 120 in the console.. Always a character type variable is gonna store in 'a' variable. So you have to make it an integer type. You can do that by.. Using

a = int(input ("enter your number "))

This line is gonna take your input and convert it into a integer type from a character type. And it is gonna store in 'a' variable.

Somu Nath
  • 33
  • 5