java打印两个整数,无法在Python 3中打印两个整数的总和

我有以下Python培训代码:

import sys

# Declare second integer, double, and String variables.

i=12

d=4.0

s="HackerRank"

# Read and save an integer, double, and String to your variables.

x=input("enter integer x:")

y=input("enter double y:")

z=input("enter string z:")

# Print the sum of both integer variables on a new line.

print(i+x)

# Print the sum of the double variables on a new line.

print(y+d)

# Concatenate and print the String variables on a new line

print(s+z)

# The 's' variable above should be printed first.

我想要实现的目标如下:

在新行上打印i加上int变量的总和 . 将d加上双变量的总和打印到新行上一位小数的比例 . 使用您读取的字符串连接s并将结果打印在新行上 .

当我运行我的代码时,我收到此错误:

回溯(最近一次调用最后一次):文件“C:... \ lesson2.py”,第12行,打印(i x)TypeError:不支持的操作数类型:'int'和'str'

你能帮帮忙吗?

EDIT: 我读了所有的评论 . 添加两个double类型时出错 . 我试过双重铸造,但它不起作用:

import sys

# Declare second integer, double, and String variables.

i=12

d=4.0

s="HackerRank"

# Read and save an integer, double, and String to your variables.

x=input("enter integer x:")

y=input("enter double y:")

z=input("enter string z:")

# Print the sum of both integer variables on a new line.

print(i+int(x))

# Print the sum of the double variables on a new line.

print(y+double(d))

# Concatenate and print the String variables on a new line

print(s+z)

# The 's' variable above should be printed first.

错误是:

回溯(最近一次调用最后一次):文件“C:... \ lesson2.py”,第14行,打印(y double(d))NameError:名称'double'未定义

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值