Hi there! 我是嘟嘟~受到前辈启发,想说可以纪录一下自己练习的过程,小女子为程式超超菜鸟,此系列非教学文,仅为个人解题笔记,可能有错误或未补充详尽之处,欢迎前辈们不吝指教!也欢迎正在自学的伙伴一起讨论学习~
Day 1: Data Types
题目已宣告3个变量i,d,s
,要求宣告3个变量符合下列规则。
输入格式
第一行包含一个必须与i
相加的整数。
第二行包含一个必须与d
加总的double(浮点数) 。
第三行包含一个必须与s
连接的字符串。
输出格式
在第一行上打印两个整数的总和,在第二行上打印两个双精度数的总和(到小数点第1位) (scaled to 1 decimal place) ,然后在第三行上打印两个串联的字符串。
样本输入
124.0is the best place to learn and practice coding!
样本输出
168.0HackerRank is the best place to learn and practice coding!
初始格式
i = 4d = 4.0s = 'HackerRank '# Declare second integer, double, and String variables.# Read and save an integer, double, and String to your variables.# Print the sum of both integer variables on a new line.# Print the sum of the double variables on a new line.# Concatenate and print the String variables on a new line# The 's' variable above should be printed first.
我的解答
i = 4d = 4.0s = 'HackerRank 'a = int(i) + int(input())b = float(d) + float(input())c = s + input()print(a)print(round(b,1))print(c)
补充:
此处double
指的是C++语言中的双倍精度浮点数,类似于Python的float
浮点数的意思。
题目有写印出的第二个浮点数要取到小数点第一位,打文章才发现,故加上round()
,可以参考文章【Python如何控制小数点后面的小数位数】