python打印三角函数 python有参函数打印等边三角形

如何用python表示三角函数

在python中,有一个math module,你可以import math,里面有math.sin(), math.cos(), math.asin()和math.acos()四个函数。相信你也知道asin和acos的意思,就是arcsin和arccos。有了这四个函数你就可以求函数值和角度了。但是要注意括号里面填的数值,要用弧度制。

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站设计制作、成都做网站、历下网络推广、微信平台小程序开发、历下网络营销、历下企业策划、历下品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供历下建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com

简单python语言编程:采用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像。

I just wrote an simple one for one other guy.

You may check it here and see if it's useful for you.

如何用python完成:用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像。

I wrote this in Tkinter for you, in case you don't know Tkinter, it is a built-in module for most python versions.

If you want a commandline version, you can ask me, but tell you what, since those values are all

float numbers, so it's hard to get a precise graph in commandline window.

Well, in this version, I enlarged each element's position by 40 and then change them to integer, guess this is an endurable loss of precision.

#

from math import radians

from math import sin

from Tkinter import *

pos = []

xPos = 0

centerX = 0

centerY = 0

for deg in range(-360, 361, 10):

pos.append([xPos, int(40*(sin(radians(deg))))]) #1000 too big for my screen

xPos+=1

if deg == 0:

centerX = xPos-1

centerY = pos[-1][1]

root = Tk()

root.title('trianble graph from -180 to 180')

width, height = 550, 450

mHei = height/2

mWid = width/2

canvas = Canvas(root, width=width, height=height)

canvas.create_line(0, mHei, width, mHei)   #x axis

canvas.create_line(mWid, 0, mWid, height)  #y axis

xStep = (width-150)/len(pos)

yStep = (height-150)/len(pos)

radius = 3

# the middle point (sin(0) is first drawn and used as position reference for all

canvas.create_oval(mWid-radius, mHei-radius, mWid+radius, mHei+radius, fill='green')

print pos

print xStep, yStep, centerX, centerY

#exit(0)

for i in pos:

if i[0] == centerX: #center processed already.

continue

x = mWid + xStep*(i[0]-centerX)

# y is smaller, the bigger the value, so use minus

y = mHei - yStep*(i[1]-centerY)

canvas.create_oval(x-radius, y-radius, x+radius, y+radius, fill='green')

canvas.pack()

root.mainloop()

Python 打印各种三角形

rows = int(input('输入列数:'))

for i in range(1, rows):

print('*' * i)

for i in range(1, rows):

for j in range(i):

print("*", end="")

print("")

rows = int(input('输入列数:'))

for i in range(1, rows):

print(' * ' * i)

for i in range(1, rows):

for j in range(1, i + 1):

print(" * ", end="")

print("")

rows = int(input('输入列数:'))

for i in range(1, rows):

if i % 2 != 0:

str = ('*' * i)

print(str.center(9, ' '))

rows = int(input('输入列数:'))

for i in range(0, rows):

print(" * " * rows)

for i in range(0, rows):

for j in range(0, rows):

print(" * ", end="")

print(" ")

for x in range(10):

for i in range(x, 10):

print('*', end='')

print('')

print('同一行打印直角三角形')

for j in range(10):

for x in range(0, j):

print(' ', end='')

for n in range(j, 19 - j):

print(' ', end='')

for k in range(0, j):

print(' ', end='')

print('')

print('直角三角形拼装心形')

for j in range(8):

for x in range(0, j):

print(' ', end='')

for n in range(j, 19 - j):

print(' ', end='')

for k in range(0, j):

print(' ', end='')

print('')

for i in range(10):

for j in range(0, 0 + i):

print(end=' ')

for k in range(0 + i, 10):

print('*', end=' ')

print('')

print('打印倒立等腰三角形1')

for j in range(10):

for x in range(0, j):

print(end=' ')

for n in range(j, 15 - j):

print('*', end='')

print('打印倒立等腰三角形2')

for i in range(10):

for j in range(0, 0 + i):

print(end=' ')

for k in range(0 + i, 10):

print('*', end=' ')

print('')

print('同一行打印两个等腰三角形')

for i in range(10):

for j in range(0, 10 - i):

print(end=' ')

for k in range(10 - i, 10):

print(' ', end=' ')

for n in range(0, 0):

print(end=' ')

for m in range(0 + i, 10):

print(' ', end=' ')

for jj in range(10, 10):

print(end=' ')

for kk in range(10 - i, 10):

print(' ', end=' ')

print('')

print('等腰三角形拼装心形')

for i in range(10):

for j in range(0, 10 - i):

print(end=' ')

for k in range(10 - i, 10):

print(' ', end=' ')

for n in range(0, 0):

print(end=' ')

for m in range(0 + i, 10):

print(' ', end=' ')

for jj in range(10, 10):

print(end=' ')

for kk in range(10 - i, 10):

print(' ', end=' ')

print('')

for i in range(20):

for j in range(0, 0 + i):

print(end=' ')

for k in range(0 + i, 20):

print('*', end=' ')

print('')

print('打印正方形')

for i in range(10):

for j in range(0, 10 - i):

print(end=' ')

for n in range(0, 0 + i):

print(end=' ')

for m in range(0 + i, 10):

print(' ', end=' ')

for k in range(10 - i, 10):

print(' ', end=' ')

print('')

在python中用while语句打印出倒三角形

#打印倒立的正三角形

hang = int(input("请输入行数:"))

y = 1

while y = hang:

space = 1

while space y:

print(" ",end="")

space += 1

x = hang - y

while x = 0:

print("* ",end="")

x -= 1

print()

y += 1

print("图形打印完成!")


新闻标题:python打印三角函数 python有参函数打印等边三角形
转载来源:http://bzwzjz.com/article/docppsh.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: app网站建设 四川成都网站建设 网站设计 成都企业网站建设 重庆网站建设 成都营销网站制作 高端网站设计 营销型网站建设 成都网站建设 盐亭网站设计 成都网站建设 企业网站建设 企业手机网站建设 响应式网站设计 成都网站制作 营销网站建设 网站建设公司 成都网站设计 网站建设改版 网站建设公司 网站制作 成都网站设计