Week 1 - Hello Python!
Practice Quiz: Introduction to Programming
1. What’s a computer program?
- A set of languages available in the computer
- A process for getting duplicate values removed from a list
- A list of instructions that the computer has to follow to reach a goal
- A file that gets copied to all machines in the network
2. What’s the syntax of a language?
- The rules of how to express things in that language
- The subject of a sentence
- The difference between one language and another
- The meaning of the words
3. What’s the difference between a program and a script?
- There’s not much difference, but scripts are usually simpler and shorter.
- Scripts are only written in Python.
- Scripts can only be used for simple tasks.
- Programs are written by software engineers; scripts are written by system administrators.
4. Which of these scenarios are good candidates for automation? Select all that apply.
- Generating a sales report, split by region and product type
- Creating your own startup company
- Helping a user who’s having network troubles
- Copying a file to all computers in a company
- Interviewing a candidate for a job
- Investigating the root cause of a machine failing to boot
5. What are semantics when applied to programming code?
- The rules for how a programming instruction is written
- The difference in number values in one instance of a script compared to another
- The intended meaning or logic of coded statements
- The end result of a programming instruction
Practice Quiz: Introduction to Python
6. Fill in the correct Python command to put “My first Python program” onto the screen.
_____("My first Python program")
- print(“My first Python program”)
7. Python is an example of what type of programming language?
- General purpose scripting language
- Machine Language
- Platform-specific scripting language
- Client-side scripting language
8. Convert this Bash command into Python:
echo Have a nice day
- print(“Have a nice day”)
9. Fill in the correct Python commands to put “This is fun!” onto the screen 5 times.
for i in range(5): _____("This is fun!")
for i in range(5):
- for i in range(5):print(“This is fun!”)
10. Why is Python relevant to IT? Select all that apply.
- Python is used in fast-growing areas of IT, like machine learning and data analytics.
- Python works well as a scripting language for IT automation.
- Python scripts run on IT servers only.
- Python can be used to calculate statistics, run e-commerce sites, process images, interact with web services, and more.
Practice Quiz: Hello World
11. What are functions in Python?
- Functions let us use Python as a calculator.
- Functions are pieces of code that perform a unit of work.
- unctions are only used to print messages to the screen.
- Functions are how we tell if our program is functioning or not.
12. What are keywords in Python?
- Keywords are reserved words that are used to construct instructions.
- Keywords are used to calculate mathematical operations.
- Keywords are used to print messages like “Hello World!” to the screen.
- Keywords are the words that we need to memorize to program in Python.
13. What does the print function do in Python?
- The print function generates PDFs and sends it to the nearest printer.
- The print function stores values provided by the user.
- The print function outputs messages to the screen
- The print function calculates mathematical operations.
14. Output a message that says "Programming in Python is fun!" to the screen.
- print(“Programming in Python is fun!”)
15. Replace the ___ placeholder and calculate the Golden ratio: 1+√5/2
Tip: to calculate the square root of a number x, you can use x**(1/2).
ratio = ___
print(ratio)
- ratio = (1 + 5**(1/2)) / 2print(ratio)
crash course on python week 1 quiz answers
Week 1 Graded Assessment
16. Once you have learned the basics of a programming language, how does this affect your ability to learn and use a second programming language?"
- You should only code in one language.
- It’s easier to learn and use a second language.
- It’s difficult to learn and use a second language.
- The syntax and semantics will be the same.
17. What is a shorter piece code, typically used to automate a specific task?
- Variable
- Syntax
- Script
- Markup
18. What are some tasks that might be a good fit for full automation? Select all that apply.
- Updating specific files on multiple computers
- Detecting and removing duplicate data
- Interviewing and hiring employees
- Haircuts and styling
19. What is the term for the set of rules for how statements are constructed in a programming language?
- Format
- Semantics
- Syntax
- Grammar
20. What is the program that reads and executes Python code by translating it to computer instructions called?
- Linker
- Interpreter
- Translator
- Compiler
21. Write a Python script that outputs "Automating with Python is fun!" to the screen. Remember that syntax precision is important in programming languages. A missing capital letter, spelling error, or punctuation mark can produce errors.
# Enter code here:_____# Should print: Automating with Python is fun!
# Enter code here:
_____
- print(“Automating with Python is fun!”)
22. What should be the output of the expression below?
print((6-2)/(5*(1+4))+3)
- 3.16
- 50.0
- 12.0
- 5.0
23. In one year, if there are 365 days, with 24 hours in a day, and 60 minutes in an hour, write a program to calculate the number of minutes in a year. Print the result on the screen. Note: Your result should be in the format of just a number, not a sentence.
# Enter code here:_____# Should print 525600
# Enter code here:
_____
- minutes_in_hour = 60hours_in_day = 24days_in_year = 365minutes_in_year = minutes_in_hour * hours_in_day * days_in_yearprint(minutes_in_year)
24. Use Python to calculate how many number-based passcodes can be formed with 10 numerals (0 through 9). For a 1 numeral passcode, there would be 10 possibilities. For a 2 numeral passcode, each numeral is independent of the other, so there would be 10 times 10 possibilities. Using this information, print the amount of possible passwords that can be formed with 8 numerals. Note: Your result should be in the format of just a number, not a sentence.
# Enter code here:____# Should print 100000000
# Enter code here:
____
- numerals = 10password_length = 8possible_passwords = numerals ** password_lengthprint(possible_passwords)
25. Consider this scenario about using Python to make calculations:
In a managed computing environment, there are 200 remote computers that must download 200 MB (megabytes) of updates each month. There are 1024 KB (kilobytes) in each MB.
Fill in the blank in the code below to compute the number of total kilobytes downloaded by these computers from the remote update server each month.
download_size_kb = 200*1024total_computers = 200total_kbs = ____
print(total_kbs) # Should print 40960000.0
download_size_kb = 200*1024
total_computers = 200
total_kbs = ____
download_size_kb * total_computers
26. What is a function?
- The beginning of a program defining who wrote it and why
- A reusable block of code that performs a specific task
- A document describing a software project
- The task a program is written to accomplish
27. What are some of the benefits of automation? Select all that apply.
- Consistency
- Can accomplish creative tasks
- More cost-effective for complex, seldom-done tasks
- Doesn’t get tired
28. What is the term for the intended meaning or effect of statements in a programming language?
- Syntax
- Grammar
- Format
- Semantics
29. Complete the code so that the string "I am writing Python code!" will print to the screen. Remember that syntax precision is important in programming languages. A missing capital letter, spelling error, or punctuation mark can produce errors.
30. What should be the output of the expression below?
print(6*2-5/(1+4)+3**2)
- 49.0
- 0.28
- 20.0
- 19.36
31. Assuming there are 60 minutes in an hour, write a program that calculates the number of minutes in a 24 hour day. Print the result on the screen. Note: Your result should be in the format of just a number, not a sentence.
32. Mercury has a diameter of approximately 1,516 miles. Earth has a diameter of approximately 3,959 miles. Use Python to calculate how much larger Earth’s diameter is than Mercury's (in miles). Note: Your result should be in the format of a number, not a sentence.
33. Consider this scenario about using Python to make calculations:
On a college campus, there are 30 computers in each of the 20 computer labs that are spread across campus. The computers have a life cycle where they are replaced every 5 years, with an equal number (one-fifth) of the computers replaced each year.
Fill in the blank to compute the number of computers that are replaced each year. Note: Your result should be in the format of just a number, not a sentence.
34. What is a computer program?
- A file that gets printed by the Python interpreter.
- The syntax and semantics of a programming language.
- The overview of what the computer will have to do to solve an automation problem.
- Step-by-step instructions on how to complete a set of tasks, to be executed by a computer.
35. Which of the following are characteristics of the Python language? Select all that apply.
- Python is cross-platform compatible
- Python is used in a wide variety of applications
- Python has many platform-specific tools, like Bash or Powershell
- Python is an object-oriented language not fit for general purpose scripting
36. Keeping in mind there are 86400 seconds per day, write a program that calculates how many seconds there are in a week, if a week is 7 days. Print the result to the screen. Note: Your result should be in the format of just a number, not a sentence.
37. Use Python to calculate how many number-based passcodes can be formed with 10 numerals (0 through 9). For a 1 numeral passcode, there would be 10 possibilities. For a 2 numeral passcode, each numeral is independent of the other, so there would be 10 times 10 possibilities. Using this information, print the amount of possible passwords that can be formed with 8 numerals. Note: Your result should be in the format of just a number, not a sentence.
38. What is the difference between syntax and semantics in a programming language?
- Syntax is a set of rules for how statements are constructed. Semantics refers to the intended meaning or effect of statements.
- Syntax is the effect the instructions have on the system and semantics are how to write the instructions.
- Syntax is the tool that executes a computer program and semantics is the development environment.
- Syntax refers to computer programs and semantics is another word for scripts.
39. Use Python to calculate how many different passwords can be formed with 6 lower case English letters (excludes any character not found in the English alphabet). For a 1 letter password, there would be 26 possibilities. For a 2 letter password, each letter is independent of the other, so there would be 26 times 26 possibilities. Using this information, print the amount of possible passwords that can be formed with 6 letters.
40. Fill in the blank to calculate how many sectors a given 16 GB (gigabyte) hard disk drive has. The given hard drive is divided into sectors of 512 bytes each. How many sectors should this drive have? Your result should be in the format of just a number, not a sentence. Note: To calculate the disk size, multiply by multiples of 1024. In the code below, the "disk_size" of 16 GB is expressed as multiplying 16 by 1024 three times to get from bytes, to kilobytes, to megabytes, and finally to gigabytes.
41. What is automation?
- The inputs and outputs of a program
- The process of replacing a manual step with an automated step
- The rules of a programming language
- The process of designing a solution to a problem
42. What is a property of Python that makes it easier to understand than some other programming languages?
- Basic guidelines can be given and it will write the code.
- You can use Python code in any other language.
- Python doesn’t have a defined syntax.
- Code is similar to the English language.
43. Which Python function will output text, or other value, to the screen?
- echo
- print()
- output()
- console.out
44. What should be the output of the expression below?
print(15+5+(3*2)/4**2+(3-7)*7)
- 15.0
- 81.0
- -7.625
- 6.0