if ==a,c=1 elif == b ,c=2 ,怎么输出a和b
时间: 2023-09-23 07:07:41 浏览: 38
你可以尝试使用 print 函数来输出 a 和 b。以下是一个示例代码:
```
a = 10
b = 20
if a == 10:
c = 1
print("a is", a)
elif b == 20:
c = 2
print("b is", b)
```
在这个例子中,如果变量 a 等于 10,则会将变量 c 赋值为 1,并且会输出 "a is 10"。如果变量 b 等于 20,则会将变量 c 赋值为 2,并且会输出 "b is 20"。由于在这个例子中只有变量 a 等于 10,所以输出的结果是 "a is 10"。
相关问题
def calculate(a,b,c): if c==0: return a+b elif c==1: return abs(a-b) elif c==2: return a*b elif c==3: return a/b elif c==4: return b/a
这是一个简单的计算函数,它接受三个参数:a,b,和c。根据c的值,函数会执行不同的计算操作并返回结果。如果c为0,则返回a和b之和;如果c为1,则返回a和b之差的绝对值;如果c为2,则返回a和b的积;如果c为3,则返回a除以b的结果;如果c为4,则返回b除以a的结果。请注意,当a或b为0时,c为3或4的情况将引发ZeroDivisionError错误。
求 a * x^2 + b * x + c = 0 方程的根。代码
好的,以下是一个求解一元二次方程的 Python 代码:
```python
import math
def solve_quadratic_equation(a, b, c):
delta = b**2 - 4*a*c
if delta < 0:
return None
elif delta == 0:
x = -b / (2*a)
return x
else:
x1 = (-b + math.sqrt(delta)) / (2*a)
x2 = (-b - math.sqrt(delta)) / (2*a)
return x1, x2
```
其中,`a`,`b`,`c` 分别代表一元二次方程 `a * x^2 + b * x + c = 0` 中的系数,函数返回方程的根。若方程无实数根,则返回 `None`。
你可以调用这个函数求解一元二次方程。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)