The document contains questions about Python basics like expressions, syntax errors, PEP8, and linters. It also covers built-in data types like strings, variables, and numbers. Other topics include functions, parameters vs arguments, control flow, and coding exercises to write functions for tasks like finding the maximum of two numbers, checking for prime numbers, and printing patterns of stars.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
40 views
Questions Py
The document contains questions about Python basics like expressions, syntax errors, PEP8, and linters. It also covers built-in data types like strings, variables, and numbers. Other topics include functions, parameters vs arguments, control flow, and coding exercises to write functions for tasks like finding the maximum of two numbers, checking for prime numbers, and printing patterns of stars.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Questions 10.
What is the result of not(True or
False)? Basics 11. Under what circumstances does the 1. What is an expression? expression 18 <= age < 65 evaluate to 2. What is a syntax error? True? 3. What is PEP8? 12. What does range(1, 10, 2) return? 4. What does a linter do? 13. Name 3 iterable objects in Python. 5. What is the result of this expression: Functions “*” * 10 1. What is the difference between a 6. What is CPython? parameter and an argument? 7. How is CPython different from Jython? 2. All functions in Python by default return 8. How is CPython different from …? IronPython? 3. What are keyword arguments and Primitive Types when should we use them? 1. What is a variable? 4. How can we make a parameter of a 2. What are the primitive built-in types in function optional? Python? 5. What happens when we prefix a 3. When should we use “”” (tripe quotes) parameter with an asterisk (*)? to define strings? 6. What about two asterisks (**)? 4. Assuming (name = “John Smith”), what 7. What is scope? does name[1] return? 8. What is the difference between local 5. What about name[-2]? and global variables? 6. What about name[1:-1]? 9. Why is using the global statement a 7. How to get the length of name? bad practice? 8. What are the escape sequences in Python? 9. What is the result of f“{2+2}+{10%3}”? Coding Exercises 10. Given (name = “john smith”), what will name.title() return? 1. Write a function that returns the 11. What does name.strip() do? maximum of two numbers. 12. What will name.find(“Smith”) return? 2. Write a function called fizz_buzz that 13. What will be the value of name after takes a number. we call name.replace(“j”, “k”)? 1. If the number is divisible by 3, it 14. How can we check to see should return “Fizz”. if name contains “John”? 2. If it is divisible by 5, it should 15. What are the 3 types of numbers in return “Buzz”. Python? 3. If it is divisible by both 3 and 5, Control Flow it should return “FizzBuzz”. 1. What is the difference between 10 / 4. Otherwise, it should return the 3 and 10 // 3? same number. 2. What is the result of 10 ** 3? 3. Write a function for checking the speed 3. Given (x = 1), what will be the value of of drivers. This function should have one after we run (x += 2)? parameter: speed. 4. How can we round a number? 1. If speed is less than 70, it 5. What is the result of float(1)? should print “Ok”. 6. What is the result of bool(“False”)? 2. Otherwise, for every 5km above 7. What are the falsy values in Python? the speed limit (70), it should give the 8. What is the result of 10 == “10”? driver one demerit point and print the 9. What is the result of “bag” > “apple”? total number of demerit points. For example, if the speed is 80, it should print: “Points: 2”. 3. If the driver gets more than 12 points, the function should print: “License suspended” 4. Write a function called showNumbers that takes a parameter called limit. It should print all the numbers between 0 and limit with a label to identify the even and odd numbers. For example, if the limit is 3, it should print: 1. 0 EVEN 2. 1 ODD 3. 2 EVEN 4. 3 ODD o Write a function that returns the sum of multiples of 3 and 5 between 0 and limit (parameter). For example, if limit is 20, it should return the sum of 3, 5, 6, 9, 10, 12, 15, 18, 20. o Write a function called show_stars(rows). If rows is 5, it should print the following: 1. * 2. ** 3. *** 4. **** 5. ***** o Write a function that prints all the prime numbers between 0 and limit where limit is a parameter.