# User Input Assignments

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

<details>

<summary>Solution</summary>

<mark style="color:green;">`length = float(input('Enter the length : '))`</mark>&#x20;

<mark style="color:green;">`breadth = float(input('Enter the length : '))`</mark>

<mark style="color:green;">`area = length * breadth`</mark>&#x20;

<mark style="color:green;">`print(f'Area : {area}')`</mark>

</details>

**`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.`**

![](https://655513900-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fan5ZGnEMAiGRLJHFykYm%2Fuploads%2Fj6hrIQdGpvOV3C49wTLh%2Fimage.png?alt=media\&token=8fe8d91f-81f4-46bc-b4f7-eef6c6f20411)

**`The Formula That we use For BMI is :`**&#x20;

$$
bmi = weight(kgs)/height(cms)^2\*10000
$$

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

<details>

<summary>Solution</summary>

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

<mark style="color:green;">`weight = int(input('Enter your weight : '))`</mark>&#x20;

<mark style="color:green;">`height = int(input('Enter your height : '))`</mark>

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

<mark style="color:green;">`bmi = round(weight / height ** 2 * 10000)`</mark>

<mark style="color:green;">`print(f'Your BMI is {bmi}')`</mark>

</details>

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

<details>

<summary><em>Solution</em></summary>

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

<mark style="color:green;">`weight = int(input('Enter your weight : '))`</mark>&#x20;

<mark style="color:green;">`height = int(input('Enter your height : '))`</mark>

<mark style="color:green;">`bmi = round(weight / height ** 2 * 10000)`</mark>

<mark style="color:green;">`print(f'Your BMI is {bmi}')`</mark>

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

<mark style="color:green;">`print('Under Weight : ', bmi<=18.5)`</mark>&#x20;

<mark style="color:green;">`print('Normal Weight : ', 24.9>=bmi>18.5)`</mark>&#x20;

<mark style="color:green;">`print('Over Weight : ', 29.9>=bmi>25)`</mark>&#x20;

<mark style="color:green;">`print('Obesity : ', bmi>=30)`</mark>

</details>

*4.* **`Take Principle, Rate, and Interest From User and Calculate Simple Interest.`**&#x20;

**`Formulae For Simple Interest is:`**&#x20;

$$
Simple Interest = Principle \* Rate \* Time / 100
$$

<details>

<summary>Solution</summary>

<mark style="color:green;">`principle = int(input('Enter the amount : '))`</mark>&#x20;

<mark style="color:green;">`rate = int(input('Rate : '))`</mark>&#x20;

<mark style="color:green;">`time = int(input('Time : '))`</mark>

<mark style="color:green;">`simple_interest = principle * rate * time / 100`</mark>&#x20;

<mark style="color:green;">`print(f'Simple Interest is {simple_interest}')`</mark>

</details>

5\. **`Your task is to take name and age  and  location from user and print the following message  :`**&#x20;

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

<details>

<summary>Solution</summary>

<mark style="color:green;">`name = input('Enter your name : ')`</mark>&#x20;

<mark style="color:green;">`age = input('What is your age ? ')`</mark>&#x20;

<mark style="color:green;">`location = input('Where do you live ? ')`</mark>

## <mark style="color:blue;">**`# Without Formatted String`**</mark>

<mark style="color:green;">`print('Hello Everyone , I am' ,name, 'and i am', age, 'years old and i live in', location,'.')`</mark>

## <mark style="color:blue;">**`# With Formatted String`**</mark>

<mark style="color:green;">`print(f'Hello Everyone , I am {name} and i am {age} years old and i live in {location}.')`</mark>

</details>

**`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.`**

<details>

<summary><em>Solution</em></summary>

<mark style="color:green;">`n = int(input('Number of Army People : '))`</mark>&#x20;

<mark style="color:green;">`g = int(input('How many groups do we need ? '))`</mark>

<mark style="color:green;">`rest = n%g`</mark>&#x20;

<mark style="color:green;">`print(f'Remaining People : {rest}')`</mark>

</details>

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

<details>

<summary>Solution</summary>

</details>

### Python User Input Questions For you to Practice :&#x20;

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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://training.gitbook.io/python-assignments/user-input-assignments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
