Loops
✕Loop Basics
Question 1 of 3
- Display numbers from 1 to 10 using both
forandwhileloops. - Assign
num_tupleas(1, 4, 7, 12, 20). Using loop, find even numbers and their sum - Assign
num_setas{1, 3, 5, 7, 9}. Using loop, find odd numbers and their product - Assign
numas7. Display it's factorial using bothforandwhileloops. - 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 listevaluated_datausing 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.
- Display numbers from 1 to 10 using both
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}.
- Record of student is stored as
Loop Challenges
Question 3 of 3
- First letter of word always have to be capital
- If preceding letter occurs earlier in dictionary then letter has to be capital
- If preceding letter occurs later in dictionary then letter has to be small
- If preceding letter is same as current letter then no change in case.
- Example:
applE is fruit=>APple IS FRUiT 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
Write function to take string as input and provide output with below condition:
