ASSIGNMENT -1:
Python Programs with Questions:-
1. Write a for loop to calculate the factorial of a number n (input from
user).
Code:
2. FizzBuzz:
Print numbers from 1 to 50.
For multiples of 3, print “Fizz”
For multiples of 5, print “Buzz”
For multiples of both 3 and 5, print “FizzBuzz
Code:
3. Inverted Triangle Pattern:
Input: n = 5
Code:
4. Number Triangle
Input: n = 5
Code:
5.Print numbers from 1 to 20 but skip number 13
Code:
6. Write a python program to keep taking integer ,inputs from the user
until the user enters 'q' (for quit)
After the user quits:
Calculate the average of the ntered numbers
Calculate the product of the entered numbers
then print both values
(You can usa a while loop)
Code:
7. You are given a number, stored in a variable with the name num.For all
numbers in the range of [1, num], including num, print the output
according to the following conditions
If the current number, is divisible by both 2 and 3. i.e. num % 2 and num
% 3 == 0 print “Both” (without quotes)
• If the number is only divisible by 2. print 'Two', without quotes
• If the number is only divisible by 3. print 'Three’ without quotes
• Else, if the number is not divisible by both 2 and 3. Print ‘None’ without quotes.
Print all values on a new line.
Code:
8. Pizza Order Program:Small pizza : Rs.100 Medium pizza : Rs.200 Large
pizza : Rs.300
Pepperoni for small pizza: Rs.30
Pepperoni for medium and large pizza : Rs.50
Extra Cheese for any size pizza : Rs. 20
Based on the user’s order (which you will take using input statements) .
Write the program to calculate the total bill.
Code:
9. Smart Home Thermostat
In a smart home system, users set a preferred temperature. Depending on
the current room temperature, the system should decide whether to
heat, cool, or take no action. Write a function
adjust_temperature(current_temp, preferred_temp) that returns one of
the following strings: "Turn on heating", "Turn on cooling", or "No action
needed".
Code:
10. Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then
using following rules print their place of service.
if employee is female, then she will work only in urban areas.
if employee is a male and age is in between 20 to 40 then he may work in
anywhere.
if employee is male and age is in between 40 t0 60 then he will work in
urban areas only. And any other input of age should print "ERROR".
Code: