What is the output of the following code? ( ) try: result = 5 / 0 +18 except ZeroDivisionError as e: print(e) A. 0 B. 10 C. division by zero D. Error 二、真假判断题(每题5分,共25分) 请在括号中填写T或F,T表示真,F表示假。 1.( )Keys in a dictionary must be unique in Python. 2.( ) Lists are mutable data types in Python.. 3.( )Sets are mutable data types in Python.. 4.( )A generator expression creates an iterable generator object that produces values on demand, which is known as lazy(惰性) evaluation. 5.( ) In Python, a value can be associated with only one key in a dictionary. 三、填空题(每题5分,共10分) 1.The expression 'js' not in 'acbed' evaluates to ____________. 2.Write the code to create a set containing the elements 11, 22, and 13. 四、程序阅读题(每题10分,共20分) 写出程序运行结果,不允许使用编程软件。 1. def test(*args): return max(args) number = [63, 100, 0, -100] result = test(*number) print(result) 2. numbers = [ 1, 9, 4, 2, 9, 5, 18, -1, 0, 12] for value in (x ** 2 for x in numbers if x % 3 != 0): print(value, end=' ') 五.编程序练习题(20分) Requirements statement: Write a program that simulates(模拟) a simple calculator(计算器). Prompt for (提示) the user to enter two numbers and an operator(+, -, *, /), then display the result (use print() and input()).
时间: 2023-12-02 07:03:38 浏览: 334
The output of the code will be "division by zero".
1. T
2. T
3. T
4. T
5. F
1. False
2. {11, 22, 13}
1. The output will be 100.
2. The output will be 1 16 4 25 324 1.
Here's the solution to the programming exercise:
```python
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
operator = input("Enter the operator (+, -, *, /): ")
result = None
if operator == "+":
result = num1 + num2
elif operator == "-":
result = num1 - num2
elif operator == "*":
result = num1 * num2
elif operator == "/":
result = num1 / num2
else:
print("Invalid operator entered.")
if result is not None:
print("Result:", result)
```
The program prompts the user to enter two numbers and an operator. It then performs the operation based on the operator entered and displays the result. If an invalid operator is entered, an error message is displayed.
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)