Loops

  1. Loop Basics

    Question 1 of 3

    • Display numbers from 1 to 10 using both for and while loops.
    • Assign num_tuple as (1, 4, 7, 12, 20). Using loop, find even numbers and their sum
    • Assign num_set as {1, 3, 5, 7, 9}. Using loop, find odd numbers and their product
    • Assign num as 7. Display it's factorial using both for and while loops.
    • Assign list with numbers. Find the second largest number in it using for loop.
    • Assign set as {1, 4, 5, 7, 8, 12}. Generate new list evaluated_data using for loop such that odd number is doubled and even number is tripled. If you encounter 4, skip evaluation for this and it you see 8, stop the loop.
  2. Using Loops

    Question 2 of 3

    • Record of student is stored as {'9843': {'course': 'Python', 'name': 'Ram', 'present': False}, {'9844': {'course': 'Java', 'name': 'Shyam', 'present': True}}. Using loop, display name of student who are absent in Python class.
    • Store a fruits names in a list. Generate a new list from it such that if fruit name starts with a/A then it has to be converted to uppercase else it has to be converted to lowercase. Use both for loop and list comprehension.
    • Write function to check if a number is prime or not. Using this function, generate list of first 20 prime numbers.
    • Write function that accepts string from user and returns a dictionary for occurrences of a character in it. Ex: apple => {'a': 1, 'p': 2, 'l': 1, 'e': 1}.
  3. Loop Challenges

    Question 3 of 3

      Write function to take string as input and provide output with below condition:
      1. First letter of word always have to be capital
      2. If preceding letter occurs earlier in dictionary then letter has to be capital
      3. If preceding letter occurs later in dictionary then letter has to be small
      4. If preceding letter is same as current letter then no change in case.
      5. Example: applE is fruit => APple IS FRUiT
      6. A => 1st Letter(upper), 1st P => Preceding(A) occur earlier (upper), 2nd P => Preceding(P) same(no_change), L => Preceding(P) occurs later (small), e => Preceding(L) occurs later(small), I => 1st letter(upper) and so on