Avionics Python Practice Questions
Avionics Python Practice Questions
Instructions:
● Prepare: Understand and plan solutions for each question.
● Code: Write Python code for each question.
● Document: Copy code and capture results in a document.
● Format: Efficiently use pages, add title page, and label solutions.
● Convert: Save as PDF with your name.
● Submit: Send PDF to avionics group on Discord.
Control Flow
6. If Statements: Write a program that checks if a given number is
positive, negative, or zero.
7. For Loops: Write a program that prints the first 10 multiples of a
given number.
8. While Loops: Write a program that keeps asking for a number until
the user types in a negative number.
9. Nested If Statements: Write a program that checks if a given year is
a leap year.
10. Range Function: Write a program that prints all prime numbers
between 1 and 50 using a f̀or̀ loop and the r̀angè function.
Lists
11. Basic Operations: Write a program that creates a list of the first
five odd numbers.
12. Indexing and Slicing: Write a program that takes a list of numbers
and prints every second element.
13. List Methods: Write a program that sorts a list of numbers in
ascending order.
14. Appending and Extending: Write a program that takes a list of
names and adds another name to the end, then extends the list with
another list of names.
15. List Comprehensions: Write a program that creates a list of
squares of even numbers between 1 and 20 using a list
comprehension.
Functions
16. Defining Functions: Write a function that takes two numbers and
returns their greatest common divisor (GCD).
17. Function Arguments: Write a function that takes a string and an
optional integer (default value 1), and prints the string repeated that
many times.
18. Default Arguments: Write a function that calculates the area of a
rectangle, where the default length and width are 1 unit each.
19. Returning Values: Write a function that takes a list of numbers
and returns a new list containing only the even numbers.
20. Recursive Functions: Write a recursive function to calculate the
nth Fibonacci number.
Dictionaries
21. Basic Operations: Write a program that creates a dictionary with
keys as student names and values as their scores.
22. Accessing and Modifying: Write a program that updates the score
of a specific student in a dictionary.
23. Dictionary Methods: Write a program that merges two
dictionaries and prints the result.
24. Iterating Through a Dictionary: Write a program that prints each
key-value pair in a dictionary of country-capital pairs.
25. Dictionary Comprehensions: Write a program that creates a
dictionary where the keys are numbers from 1 to 5 and the values are
their factorials.
Strings
26. Concatenation: Write a program that concatenates two strings
with a space in between.
27. String Methods: Write a program that takes a string and prints it
in lowercase, uppercase, and title case.
28. String Slicing: Write a program that takes a string and prints its
first half.
29. String Replacement: Write a program that replaces all vowels in a
string with the letter 'x'.
30. Checking Substrings: Write a program that checks if a given word
is a palindrome.
Input/Output
31. Basic Input: Write a program that takes a user's age and calculates
the year they were born.
32. Reading from a File: Write a program that reads the first 10 lines
of a text file.
33. Writing to a File: Write a program that takes a string from the user
and writes it to a text file, appending it if the file already exists.
34. Appending to a File: Write a program that appends a given list of
strings to a text file, each string on a new line.
35. File Line Count: Write a program that reads a text file and prints
the number of words.
Modules
36. Random Module: Write a program that generates a random
password with 8 characters.
37. Math Module: Write a program that calculates the area of a circle
given its radius using the m̀ath̀ module.
38. Datetime Module: Write a program that calculates the number of
days until a user's next birthday.
39. OS Module: Write a program that lists all files and directories in
the current directory.
40. CSV Module: Write a program that reads a CSV file of student
names and scores, and prints the names and scores of students who
scored above 80.