python 查找数字_Python程序查找两个数字的和

python 查找数字

Given two integer numbers and we have to find their sum in Python.

给定两个整数,我们必须在Python中找到它们的总和。

In the given below example, we have two variables num1 and num2 and assigning them with the value 10 and 20, finding and printing the sum of the numbers. Later we are inputting two numbers from the input and assigning them num1 and num2.

在下面给出的示例中,我们有两个变量num1和num2并为其分配值10和20,查找并打印数字的总和。 稍后,我们从输入中输入两个数字,并为其分配num1和num2 。

Note: While inputting numbers from using input() function, we get string value, to convert string value to an integer value – we need to convert them into integer. To convert string to an integer, use int() function.

注意:在使用input()函数输入数字时,我们会得到字符串值,将字符串值转换为整数值–我们需要将它们转换为整数。 要将字符串转换为整数,请使用int()函数。

Python中字符的ASCII值 (ASCII value of character in Python)

In python, to get an ASCII code of a character, we use ord() function. ord() accepts a character and returns the ASCII value of it.

在python中,要获取字符的ASCII码,我们使用ord()函数。 ord()接受一个字符并返回其ASCII值。

Example code:

示例代码:

    num1 = input("Enter first  number: ")
    num2 = input("Enter second number: ")
    sum = int(num1) + int(num2)

Example:

例:

    Input:
    num1 = 10
    num2 = 20

    Finding sum:
    sum = num1 + num2

    Output:
    30

Python code to find sum of two numbers

Python代码查找两个数字的和

# python program to find sum of 
# two numbers

num1 = 10
num2 = 20

# finding sum 
sum = num1 + num2

# printing sum
print("sum of ", num1, " and ", num2, " is = ", sum)

# taking input from user
num1 = input("Enter first  number: ")
num2 = input("Enter second number: ")

# finding sum 
sum = int(num1) + int(num2)

# printing sum
print("sum of ", num1, " and ", num2, " is = ", sum)

Output

输出量

sum of  10  and  20  is =  30
Enter first  number: 100
Enter second number: 200
sum of  100  and  200  is =  300


翻译自: https://www.includehelp.com/python/find-sum-of-two-numbers.aspx

python 查找数字

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值