0% found this document useful (0 votes)
431 views

Basic Python Coding Questions IGCSE Grade 9

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)
431 views

Basic Python Coding Questions IGCSE Grade 9

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
You are on page 1/ 3

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

You might also like