0% found this document useful (0 votes)
746 views3 pages

Python Coding Exercises for IGCSE

Uploaded by

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

Python Coding Exercises for IGCSE

Uploaded by

Hardik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Find Maximum and Minimum in a List
  • Counting Characters in a String
  • Replace Elements in a List
  • Sum of Numbers with a While Loop
  • Average of Random Numbers
  • String Manipulation with Slicing
  • Reverse Each Word in a Sentence
  • Randomly Shuffle a List
  • List Manipulation with Even and Odd Numbers
  • Write Trace Table for the Code
  • Countdown with a For Loop

1.

Sum of Numbers with a While Loop


• Use a while loop to keep asking the user for numbers and adding them to a
list called user_numbers. Stop when the user enters "done".
• Calculate and print the sum of all numbers in the list.

2. Replacing Elements in a List


• Create a list called items with values: ["pen", "notebook", "eraser", "pencil",
"marker"].
• Use a for loop to replace each item in the list with the string "sold out" if
the item's name starts with the letter "p".
• Print the updated list at the end.

3. Average of Random Numbers


• Create an empty list called random_numbers.
• Use a for loop to generate 10 random numbers between 1 and 100, and add
each to the list.
• Calculate and print the average of the numbers in random_numbers.

4. Find Maximum and Minimum in a List


• Create a list of numbers called temperatures with 7 random values between
-10 and 35 (you can hard-code these values).
• Use a loop to find and print the maximum and minimum temperatures in
the list.

5. Counting Characters in a String


• Ask the user to enter a sentence and store it in a variable called sentence.
• Use a for loop to count and print how many times the letter "e" appears in
sentence.

6. String Manipulation with Slicing


• Ask the user to enter a word and store it in input_word.
• Print the following:
o The word with every second letter (e.g., "example" → "eape").
o The middle three letters of the word (if the word has an odd length
greater than 3).

7. List Manipulation with Even and Odd Numbers


• Create a list of numbers called mixed_numbers with at least 10 random
integers.
• Separate the even and odd numbers into two new lists, even_numbers and
odd_numbers.
• Print both lists at the end.

8. Reverse Each Word in a Sentence


• Ask the user to enter a sentence and store it in a variable called sentence.
• Split the sentence into words and reverse each word individually, then join
them back into a single string.
• Print the modified sentence.

9. Randomly Shuffle a List


• Create a list called fruits with values: ["apple", "banana", "cherry", "date",
"fig", "grape"].
• Use a loop and the random module to shuffle the elements in the list.
• Print the shuffled list at the end.

10. Countdown with a For Loop


• Ask the user to enter a starting number for a countdown.
• Use a for loop to count down to zero, printing each number along the way.
• When the countdown reaches zero, print "Liftoff!".

11. Write Trace table for the code

1. Sum of Numbers with a While Loop 
• Use a while loop to keep asking the user for numbers and adding them to a 
list called
• Use a for loop to count and print how many times the letter "e" appears in 
sentence. 
 
6. String Manipulation with Slicin
• Use a loop and the random module to shuffle the elements in the list. 
• Print the shuffled list at the end. 
 
10. Countdo

You might also like