inp_name = input('Please input your name - ')
print('Welcome', inp_name)
inp_height = input('Please input your height in metre - ')
inp_weight = input('Please input your weight in kg - ')
print(inp_name, ', your bmi is :')
bmi = int(inp_weight)/(int(inp_height) ** 2)
print(bmi)
            Asked
            
        
        
            Active
            
        
            Viewed 91 times
        
    -1
            
            
         
    
    
        khelwood
        
- 55,782
- 14
- 81
- 108
- 
                    you also maybe want to think about do you want int or float. Int is a whole number so for height you could be 1m or 2m. If you want to be 1.73m then you need to use floats – Chris Doyle Feb 26 '21 at 14:27
1 Answers
0
            
            
        Simply add "int" infront of where you are asking for inputs, like so:
inp_name = str(input('Please input your name - '))
print('Welcome', inp_name)
inp_height = int(input('Please input your height in metre - '))
inp_weight = int(input('Please input your weight in kg - '))
print(inp_name, ', your bmi is :')
bmi = int(inp_weight)/(int(inp_height) ** 2)
print(bmi)
You can see that I have also added str on the first line, this will make it so the user can only input a string. You can also ask for a float by adding float, like this: float(input("Input a float: ")).
EDIT: Furthermore, if a user doesn't input the data type you are asking for, an error will occur:
You can stop this error by adding a "try: except:":
try:
    inp_height = int(input("Please input your height in metres: "))
    print(inp_height)
except: 
    print("Enter the correct data type")
This will catch any errors that happen.
 
    
    
        Insula
        
- 999
- 4
- 10
- 
                    1Putting `str(...)` around `input(...)` accomplishes nothing. `input` always returns a string. – khelwood Feb 26 '21 at 16:54
- 
                    @khelwood Ah okay! I honestly thought this but I thought it was best practice just to use str() when you want a string input. I guess you can use "if variable str:" to accept strings as inputs. Thank you for your comment though, always good to learn these things! – Insula Feb 26 '21 at 20:40
 
    