HackerRank闯关之路(学习ing)

**HackerRank

ps.python

Day 0

# Read a full line of input from stdin and save it to our dynamically typed variable, input_string.
input_string = input()

# Print a string literal saying "Hello, World." to stdout.
print('Hello, World.')

print(input_string)

# TODO: Write a line of code here that prints the contents of input_string to stdout.

  • LOOPS
    The provided code stub reads and integer, , from STDIN. For all non-negative integers n, print ii .*
if __name__ == '__main__':
    n = int(input())
    if n<1 or n>20:
        print('1<=n<=20')

    for i in range(0,n) :
        print(i*i)

Day 1

i = 4
d = 4.0
s = 'HackerRank '
# Declare second integer, double, and String variables.
i1 = int(input())
d1 = float(input())
s1 = str(input())

print(i+i1)
print(d+d1)
print(s+s1)
# 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.

- Write a function
Given a year, determine whether it is a leap year. If it is a leap year, return the Boolean True, otherwise return False.
Note that the code stub provided reads from STDIN and passes arguments to the is_leap function. It is only necessary to complete the is_leap function.

def is_leap(year):
    leap = False
    
    if year in range(1900,pow(10,5)+1):
        if year % 4 == 0:
            if year % 100 != 0:
                leap = True
            elif year % 400 == 0:
                leap = True
    # Write your logic here
    return leap

year = int(input())
print(is_leap(year))

Day 2: Operators

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the solve function below.
def solve(meal_cost, tip_percent, tax_percent):
    totalCost = tip = tax = 0
    tip=tip_percent*meal_cost/100 
    
    tax = tax_percent*meal_cost/100
    
    totalCost =meal_cost + tip + tax

    return int(round(totalCost))
    

if __name__ == '__main__':
    meal_cost = float(input())

    tip_percent = int(input())

    tax_percent = int(input())

        
    totalCost = solve(meal_cost, tip_percent, tax_percent)
    
        
    print(totalCost)
  • Print Function
    例如:输入n=5,输出1234
if __name__ == '__main__':
    n = int(input())
    [print(i+1, end = '') for i in range(n)]

#Day3 : Intro to Conditional Statements

  #!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input())
    if n<1 or n>100:
        print('1<=n<=100')
    if n % 2 != 0 :
        print('Weird')
    if n % 2 == 0 and n  in range(2,6) :
        print ('Not Weird')
    if n %2 == 0 and n in range (6,21):
        print('Weird')
    if n%2==0 and n>20:
        print('Not Weird')
#不知道为啥子,合在一起写就有错误

Day 4: Class vs. Instance

class Person:
    def __init__(self,initialAge):
        # Add some more code to run some checks on initialAge

        if initialAge<0:
            print("Age is not valid, setting age to 0.")
        else :
            self
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值