Summary
You have reached the end of this topic. In this topic, you learned how to:
You also had a chance to practice some code using the Code Challenges. Here are some ideal solutions for these code challenges.
Code Challenge 1
Problem Statement
Write suitable arithmetic expressions for the displayed descriptions.
Ideal Solution
1. Sum of 21 and 62
21+62
2. Difference between 43 and 17
43-17
3. 36 mod 5
35%5
4. Sum of 6 and 4 multiplied by 10
(6+4)*10
5. 23 to the 5th power
23**5
6. An expression that will result in 19 and which includes multiplication
4*5-1
7. Sum of 177 mod 4 and 223 mod 5
(177%4)+(223%5)
8. Difference between 3rd power of 14 and 3rd power of 13
14**3-13**3
9. An expression that will result in 0, which does not include multiplication and contains at least 3 arithmetic operators
(27%11)+10-15
10. An expression that includes all six arithmetic operators, addition (+), subtraction (-), multiplication (*), division (/), modulo (%) and power (**)
((20*3+5-8)/3**2)%4
Code Challenge 2
Problem Statement
Ideal Response
In the given code, add the text that will display the text, Hello World!
print("Hello World!")
Code Challenge 3
Problem Statement
Result
Conduct this experiment. Run the following program to see what happens. Note your observations so that you can revisit them when you learn about data types.
a = input("Enter any number: ")
b = input("Enter any number: ")
print(a+b)
>>> a = input("Enter any number: ")
Enter any number: 7
>>> b = input("Enter any number: ")
Enter any number: 1
>>> print(a+b)
71
Explanation: By default, the input() function in Python takes values as a string. So when we use the addition operator, +, on these values, they are concatenated or joined rather than added. You will learn more about this and how to actually convert the input into the required data type in the following topics.
- Use the Python interpreter, IDLE.
- Write a basic program to display the text, Hello World.
You also had a chance to practice some code using the Code Challenges. Here are some ideal solutions for these code challenges.
Code Challenge 1
Problem Statement
Write suitable arithmetic expressions for the displayed descriptions.
Ideal Solution
1. Sum of 21 and 62
21+62
2. Difference between 43 and 17
43-17
3. 36 mod 5
35%5
4. Sum of 6 and 4 multiplied by 10
(6+4)*10
5. 23 to the 5th power
23**5
6. An expression that will result in 19 and which includes multiplication
4*5-1
7. Sum of 177 mod 4 and 223 mod 5
(177%4)+(223%5)
8. Difference between 3rd power of 14 and 3rd power of 13
14**3-13**3
9. An expression that will result in 0, which does not include multiplication and contains at least 3 arithmetic operators
(27%11)+10-15
10. An expression that includes all six arithmetic operators, addition (+), subtraction (-), multiplication (*), division (/), modulo (%) and power (**)
((20*3+5-8)/3**2)%4
Code Challenge 2
Problem Statement
Ideal Response
In the given code, add the text that will display the text, Hello World!
print("Hello World!")
Code Challenge 3
Problem Statement
Result
Conduct this experiment. Run the following program to see what happens. Note your observations so that you can revisit them when you learn about data types.
a = input("Enter any number: ")
b = input("Enter any number: ")
print(a+b)
>>> a = input("Enter any number: ")
Enter any number: 7
>>> b = input("Enter any number: ")
Enter any number: 1
>>> print(a+b)
71
Explanation: By default, the input() function in Python takes values as a string. So when we use the addition operator, +, on these values, they are concatenated or joined rather than added. You will learn more about this and how to actually convert the input into the required data type in the following topics.
Comments
Post a Comment