Python Assignments
  • Python Assignments
  • Operators Assignment
  • User Input Assignments
  • String Assignments
  • Conditional Statements - Assignments
  • Loops - Assignments
  • List Assignments
  • Function Practice Questions
  • File Handling Assignments
  • Miscellaneous Python Assignments
Powered by GitBook
On this page

User Input Assignments

PreviousOperators AssignmentNextString Assignments

Last updated 2 years ago

  1. Take input of the length and breadth of a rectangle from the user and print the area of it.

Solution

length = float(input('Enter the length : '))

breadth = float(input('Enter the length : '))

area = length * breadth

print(f'Area : {area}')

2. Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women. The Table below shows how healthy you are with respect to your BMI.

The Formula That we use For BMI is :

Take Weight and height from the user and Calculate BMI.​

Solution

First we will take weight and height from user with the help of user input.

weight = int(input('Enter your weight : '))

height = int(input('Enter your height : '))

Then we will calculate BMI , Now say if we want only two decimal values , we can use round() Function.

bmi = round(weight / height ** 2 * 10000)

print(f'Your BMI is {bmi}')

3. Now that you have Calculated BMI , Find out whether user is Underweight or Normal Weight or Falls in what Category.

Solution

First, We will Calculate BMI, So we are going to use script we have used to calculate BMI.

weight = int(input('Enter your weight : '))

height = int(input('Enter your height : '))

bmi = round(weight / height ** 2 * 10000)

print(f'Your BMI is {bmi}')

Now that you have calculated BMI, We need to compare it BMI with Weight Status.

print('Under Weight : ', bmi<=18.5)

print('Normal Weight : ', 24.9>=bmi>18.5)

print('Over Weight : ', 29.9>=bmi>25)

print('Obesity : ', bmi>=30)

4. Take Principle, Rate, and Interest From User and Calculate Simple Interest.

Formulae For Simple Interest is:

Solution

principle = int(input('Enter the amount : '))

rate = int(input('Rate : '))

time = int(input('Time : '))

simple_interest = principle * rate * time / 100

print(f'Simple Interest is {simple_interest}')

5. Your task is to take name and age and location from user and print the following message :

Hello Everyone , I am xyz and i am xyz years old and i live in xyz.

Solution

name = input('Enter your name : ')

age = input('What is your age ? ')

location = input('Where do you live ? ')

# Without Formatted String

print('Hello Everyone , I am' ,name, 'and i am', age, 'years old and i live in', location,'.')

# With Formatted String

print(f'Hello Everyone , I am {name} and i am {age} years old and i live in {location}.')

6. Suppose there are many N numbers of people in the Army. We need to distribute them in G groups. Take the number of people from users and the Number of Groups and tell how many are left without Group.

Solution

n = int(input('Number of Army People : '))

g = int(input('How many groups do we need ? '))

rest = n%g

print(f'Remaining People : {rest}')

7.Take Temperature in fahreinheit and convert it into celcius.

Solution

Python User Input Questions For you to Practice :

  1. Write a Python program that asks the user to enter two numbers, and then prints out the sum of the two numbers.

  2. Write a Python program that asks the user to enter a string, and then prints out the length of the string.

  3. Write a Python program that asks the user to enter a sentence, and then prints out the number of words in the sentence.

  4. Write a Python program that asks the user to enter a number, and then prints out whether the number is even or odd.

  5. Write a Python program that asks the user to enter a temperature in Celsius, and then converts the temperature to Fahrenheit and prints out the result. (Hint: the formula for converting Celsius to Fahrenheit is F = (C * 9/5) + 32)

  6. Write a Python program that asks the user to enter two numbers, and then prints out the remainder of the division of the first number by the second number.

  7. Write a Python program that asks the user to enter three numbers, and then calculates and prints out the average of the three numbers.

  8. Write a Python program that asks the user to enter their age, and then prints out a message that says "You have lived [number of days] days so far!" (assuming that each year has 365 days)

  9. Write a Python program that asks the user to enter a decimal number, and then rounds the number to the nearest integer and prints out the result.

  10. Write a Python program that asks the user to enter a temperature in Celsius, and then converts the temperature to Kelvin and prints out the result. (Hint: the formula for converting Celsius to Kelvin is K = C + 273.15)

  11. Write a Python program that asks the user to enter a length in feet, and then converts the length to meters and prints out the result. (Hint: the formula for converting feet to meters is m = ft / 3.2808)

  12. Write a Python program that asks the user to enter a number, and then checks whether the number is a perfect square or not. (Hint: a perfect square is a number that is equal to the square of an integer)

  13. Write a Python program that asks the user to enter a distance in kilometers, and then converts the distance to miles and prints out the result. (Hint: the formula for converting kilometers to miles is mi = km / 1.609)

  14. Write a Python program that asks the user to enter a number, and then checks whether the number is positive, negative, or zero.

  15. Write a Python program that asks the user to enter a weight in kilograms, and then converts the weight to pounds and prints out the result. (Hint: the formula for converting kilograms to pounds is lb = kg * 2.2046)

bmi=weight(kgs)/height(cms)2∗10000bmi = weight(kgs)/height(cms)^2*10000bmi=weight(kgs)/height(cms)2∗10000
SimpleInterest=Principle∗Rate∗Time/100Simple Interest = Principle * Rate * Time / 100SimpleInterest=Principle∗Rate∗Time/100