Decision(if-elif-else)

1. Determine weather conditions based on temperature

Given an integer as an input, it represents the temperature in centigrade. Determine the weather conditions based on the temperature.

  • Temperature < 0 then print “Freezing weather”.
  • Temperature 0 – 10 then print “Very cold weather”.
  • Temperature 10 – 20 then print “Cold weather”.
  • Temperature 20 – 30 then print “Normal in temperature”.
  • Temperature 30 – 40 then print “Its Hot”.
  • Temperature >= 40 then print “Its Very Hot”.

Input:

42

    where:

  • Input represents the temperature in centigrade.

Output:

Its very hot

For Loop

table of any number

n = int(input("Enter the number "))  
for i in range(1,11):  
    c = n*i  
    print(n,"*",i,"=",c)  

Print out the individual characters of each of the words within the list

words= ['rambha','jaya','rohit','rahul','kalpana' ]
for word in words:
  print ("The following lines will print each letters of "+word)
    for letter in word:
      print (letter) 

list of integers and print the sum of positive numbers

nums = [1, 2, -3, 4, -5, 6]
sum_positives = 0
for num in nums:
  if num < 0:
    continue
  sum_positives += num
 
print(f'Sum of Positive Numbers: {sum_positives}')

Python program to iterate over dictionaries using for loops.

d = {'Red': 1, 'Green': 2, 'Blue': 3}
for color_key, value in d.items():
    print(color_key, 'corresponds to ', d[color_key]) 

Track the count of the letters from the string.

str1 = 'elearners' 
my_dict = {}
for letter in str1:
    my_dict[letter] = my_dict.get(letter, 0) +1
print(my_dict)

Nested For Loop

Print each adjective for every fruit

adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]

for x in adj:
  for y in fruits:
    print(x, y)

pyramid of numbers

rows = int(input("Enter the rows"))  for i in range(0,rows+1):      for j in range(i):          print(i,end = '')      print()