0% found this document useful (0 votes)
2 views6 pages

Python 1st Assignment

The document contains five Python programming tasks. Each task involves user input and conditional statements to provide feedback or calculations based on the input. The tasks cover topics such as hydration tracking, billing calculations, a login system, scholarship eligibility, and a guessing game.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Python 1st Assignment

The document contains five Python programming tasks. Each task involves user input and conditional statements to provide feedback or calculations based on the input. The tasks cover topics such as hydration tracking, billing calculations, a login system, scholarship eligibility, and a guessing game.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

QUESTION 1: Write a Python program that:

1. Asks the user to enter how many liters of water they drank today

2. Prints:

"Excellent Hydration" if intake ≥ 3 liters

"Adequate Hydration" if intake ≥ 2 and < 3

"Dehydrated" if intake < 2

3. Print the data type of the input value

water=input("how many liters of water you drank


today:")
print("data type of water is",type(water))
water=float(water)
if(water>=3):
print("Excellent Hydration")
elif(water>=2 and water<3):
print("Adequate Hydration")
elif(water<2):
print("Dehydrated")
,,,,,,,,,,,,,,

how many liters of water you drank today:4

data type of water is <class 'str'>

Excellent Hydration

QUESTION 2: Write a Python program that:

1. Takes units consumed as input


2. Applies the following rates:

First 100 units → 10 per unit

Next 100 units → 15 per unit

Above 200 units → 20 per unit

3. Calculates and prints the total bill

units=float(input("units consumed:"))

if(units<=100):

bill=units*10

elif(units<=200):

bill=(100*10)+((units-100)*15)

else:

bill=(100*10)+(100*15)+((unit-200)*20)

print("total bill is",bill)

………………………..

units consumed:154

total bill is 1810.0

QUESTION 3: Create a simple login system:

• Correct username: "admin"

• Correct password: "1234"


Program should:

1. Keep asking the user for username and password

2. Print "Login Successful" when correct

3. Print "Invalid Credentials" otherwise

4. Stop only when correct details are entered

Correct_username="admin"

Correct_password="1234"

while True:

username=str(input("enter username:"))

password=str(input("enter password:"))

if(username==Correct_username and password==Correct_password):

print("Login Successful")

break

else:

print("Invalid Credentials")

,,,,,,,,,,,,,,,,,

enter username:asd

enter password:d

Invalid Credentials

enter username:aae

enter password:1558

Invalid Credentials

enter username:admin

enter password:1234

Login Successful
QUESTION 4: Write a program that:

1. Takes student marks and attendance percentage as input

2. Applies rules:

o Marks ≥ 90 AND attendance ≥ 80 → "Full Scholarship" o

Marks ≥ 75 OR attendance ≥ 70 → "Partial Scholarship" o

Otherwise → "No Scholarship

marks=float(input("enter your marks:"))

attendance_percentage=float(input("enter your attendance

percentage:"))

if(marks>=90 and attendance_percentage>=80):

print("Full Scholarship")

elif(marks>=75 or attendance_percentage>=70):

print("Partial Scholarship")

else:

print("No Scholarship")

,,,,,,,,,,,,,,,,,,,,,

enter your marks:75

enter your attendance percentage:82


Partial Scholarship

QUESTION 5: Write a program where:

• The secret number is 10 • The user keeps guessing until correct

Program should:

• Print "Too High" if guess is greater

• Print "Too Low" if guess is smaller

• Print "Correct Guess!" when right and stop

secret_number=10

while True:

number=float(input("guess the secret number:"))

if(number>secret_number):

print("Too High")

elif(number<secret_number):

print("Too Low")

elif(number==secret_number):

print("Correct Guess!")

break

…….

guess the secret number:4

Too Low

guess the secret number:4


Too Low

guess the secret number:54

Too High

guess the secret number:10

Correct Guess!

You might also like