0% found this document useful (0 votes)
16 views4 pages

Programming For Business 3

The document contains three separate Python programs. The first program calculates the percentage of calories from fat in food, the second allocates university seats based on F.Sc. and NTS marks, and the third recommends a car based on user preferences regarding children, money, and truck preference. Each program includes input validation and error handling for user inputs.

Uploaded by

salmantanzeem107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Programming For Business 3

The document contains three separate Python programs. The first program calculates the percentage of calories from fat in food, the second allocates university seats based on F.Sc. and NTS marks, and the third recommends a car based on user preferences regarding children, money, and truck preference. Each program includes input validation and error handling for user inputs.

Uploaded by

salmantanzeem107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PROGRAMMING FOR BUSINESS

(24K-7300)

QUESTION 1

# Program to calculate percentage of calories from fat

def main():

try:

# Input

total_calories = float(input("Enter the total number of calories in the food: "))

fat_grams = float(input("Enter the number of fat grams in the food: "))

# Input validation

if total_calories < 0 or fat_grams < 0:

print("Error: Calories and fat grams cannot be negative.")

return

calories_from_fat = fat_grams * 9

if calories_from_fat > total_calories:

print("Error: Calories from fat cannot exceed total calories. Check your inputs.")

return

# Calculate percentage

percentage_of_fat = (calories_from_fat / total_calories) * 100

# Output

print(f"Percentage of calories from fat: {percentage_of_fat:.2f}%")

if percentage_of_fat < 30:

print("This food is low in fat.")

except ValueError:
print("Error: Please enter valid numerical inputs.")

main()

QUESTION 2

# Program to allocate university seat based on F.Sc. and NTS marks

def main():

try:

# Input

fsc_marks = float(input("Enter your F.Sc percentage: "))

nts_marks = float(input("Enter your NTS percentage: "))

# Validation

if fsc_marks < 0 or fsc_marks > 100 or nts_marks < 0 or nts_marks > 100:

print("Error: Marks should be between 0 and 100.")

return

# Allocation logic

if fsc_marks > 70 and nts_marks >= 70:

print("You qualify for IT at Oxford University.")

elif fsc_marks > 70 and nts_marks >= 60:

print("You qualify for Electronics at Oxford University.")

elif fsc_marks > 70 and nts_marks >= 50:

print("You qualify for Telecommunication at Oxford University.")

elif 70 >= fsc_marks >= 60 and nts_marks >= 50:

print("You qualify for IT at MIT.")

elif 59 >= fsc_marks >= 50 and nts_marks >= 50:

print("You qualify for Chemical at MIT.")

elif 50 > fsc_marks >= 40 and nts_marks >= 50:


print("You qualify for Computer at MIT.")

else:

print("You do not qualify for any program.")

except ValueError:

print("Error: Please enter valid numerical inputs.")

main()

QUESTION 3

# Program to recommend a car based on user preferences

def main():

# Input

children = input("Do you have children? (yes/no): ").strip().lower()

money = input("Do you have lots of money? (yes/no): ").strip().lower()

trucks = input("Do you like trucks? (yes/no): ").strip().lower()

# Determine car

if children == "no" and money == "yes":

if trucks == "no":

print("Recommended car: Porsche")

elif trucks == "yes":

print("Recommended car: Yukon")

elif children == "no" and money == "no":

print("Recommended car: Civic")

elif children == "yes" and money == "yes":

if trucks == "no":

print("Recommended car: Villager")

elif trucks == "yes":


print("Recommended car: Explorer")

elif children == "yes" and money == "no":

print("Recommended car: Sentra")

else:

print("Error: Invalid input. Please answer with 'yes' or 'no'.")

main()

You might also like