一、构显国际橡棋8x8棋盘
#!/usr/bin/env python3 #-*- coding:utf-8 -*- color_0="\033[41m \033[00m" color_1="\033[46m \033[00m" def line(a, b): for i in range(0,48): if ((i // 8) % 2) == 0: print(a, end=‘‘) else: print(b, end=‘‘) for x in range(0, 24): if ((x // 4) % 2) != 0: line(color_0, color_1) else: line(color_1, color_0) print(‘\n‘, end=‘‘)
二、求正整数平方根
#!/usr/bin/env python3 #-*- coding: utf-8 -*- #Author: fanhui num = input("Please input a number: ") num_sqrt = round(float(num)**0.5, 4) print(num, "‘s sqrt is ", num_sqrt, sep=‘‘)
[email protected] ~/py_script $ python3 num_sqrt.py Please input a number: 10 10‘s sqrt is 3.1623
三、求负整数平方根
#!/usr/bin/python3 #-*- coding: utf-8 -*- import cmath num = input("Please input a negative num: ") negative_sqrt = cmath.sqrt(float(num)) print(negative_sqrt)
[email protected] ~/py_script $ python3 negative_sqrt.py Please input a negative num: -4 2j
四、
时间: 2024-10-06 18:27:54