【Python Practice】Day 2- Question 4-9

'''
@Author: your name
@Date: 2020-07-06 11:29:47
@LastEditTime: 2020-07-06 23:25:41
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day2.py
'''
import numpy as np


# Question4:
# Write a program which accepts a sequence of comma-separated numbers
#  from console and generate a list and a tuple which contains every number.
# Suppose the following input is supplied to the program:

def Q4():
    l=input().split(',')
    # l=np.loadtxt("test.txt",comments="#",delimiter=',')
    
    t=tuple(l)

    print(l)
    print(t)


# Question5:
# Define a class which has at least two methods:

# getString: to get a string from console input
# printString: to print the string in upper case.
# Also please include simple test function to test the class methods.

class Q5():
    def get_str(self):
        self.str=input()
    
    def print_str(self):
        print(self.str.upper())     # 输出大写


# Question6:
# Write a program that calculates and prints the value according to the given formula:

# Q = Square root of [(2 _ C _ D)/H]

# Following are the fixed values of C and H:

# C is 50. H is 30.

# D is the variable whose values should be input to your program in a comma-separated sequence.
# For example Let us assume the following comma separated input sequence is given to the program:

    
import math 
def cal(D):
    C,H = 50,30
    return math.sqrt((2*C*D)/H)

def Q6():
    
    l=input().split(',')
    print(l)
    l=[int(i) for i in l]
    print(l)
    l=[cal(i) for i in l]
    print(l)
    l=[round(i) for i in l]
    print(l)
    l=[str(i) for i in l]
    print(','.join(l))   # join合并的sequence只能是字符,因此上一步需要把它变为str()

# Question 7
# 输入row,col,生成一个row*col的矩阵,这个矩阵在对应的位置上的数字为行和列的乘积
def Q7():
    import numpy as np
    x,y=map(int,input().split(','))

    print(x,y)
    arr=[]
    for num in range(0,x):
        tmp=[]
        for j in range(0,y):
            tmp.append(int(num*j))
        arr.append(tmp)
    print(np.asarray(arr))


# Question 8
# 输入一个逗号隔开的字母序列,输出排序后的序列
def Q8():
    # input_seq=[x for x in input().split(',')]
    input_seq=input().split(',')

    print(input_seq)
    input_seq.sort()
    print(','.join(input_seq))


# Question9:
# Write a program that accepts sequence of lines as input 
# and prints the lines after making all characters in the sentence capitalized.
# 输入句子序列,变为大写并打印

def Q9():
    lines=[]
    while(1):
        s=input()
        if s:
            lines.append(s.upper())
        else:
            break
    for line in lines:
        print(line)


if __name__ == "__main__":
    # Q4()

    # q5=Q5()
    # q5.get_str()
    # q5.print_str()

    # Q6()

    # Q7()

    # Q8()

    Q9()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tech沉思录

点赞加投币,感谢您的资瓷~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值