import decimal #精确浮点数,python的float不精确
#使用:
text=f.read()
Matrix=[ [decimal.Decimal(tt) for tt in t.split()] for t in text.splitlines() ]
#替换掉以下
# contents=f.read()
# number_strings=string.split(contents)
# Matrix=[]
# for i in range(5):
# row=[float(number_strings[5*i+j]) for j in range(5)]
# Matrix.append(row)
#使用 np.transpose 进行矩阵转置
print np.transpose(Matrix)
㈡ python 编程作业
这个题的逻辑题目都很清楚地写了,只需要照着实现就行了。关键是多调试看运行效果。
㈢ Python的几个编程作业..求教TAT刚开始学....
作业要自己做
#!/usr/bin/env python
print '''I have 3 kinds of fruit:
apple: $1.29/lb
grage: $2.29/lb
orange: $1.5/lb'''
choice = raw_input('Which one do you want? ')
if choice == 'grape':
weight = float(raw_input('Ok, grape. How many pounds do you want? '))
print 'the cost is', round(weight*2.29,2)
elif choice == 'apple':
weight = float(raw_input('Ok, apple. How many pounds do you want? '))
print 'the cost is', round(weight*1.29,2)
elif choice == 'orange':
weight = float(raw_input('Ok, orange. How many pounds do you want? '))
print 'the cost is', round(weight*1.5,2)
else:
print 'Sorry, we don\'t have that.'
#!/usr/bin/env python
def smallest(x,y,z):
temp = y if y<z else z
return x if x<temp else temp
a = float(raw_input('Enter the 1st number: '))
b = float(raw_input('Enter the 2nd number: '))
c = float(raw_input('Enter the 3rd number: '))
print smallest(a,b,c),'is the smallest.'
#!/usr/bin/env python
left = int(raw_input('Enter the beginning integer: '))
right = int(raw_input('Enter the ending integer: '))
print ("All the integers between %d and %d that are divisible by both 3 and 7 are:" %(left,right))
for i in range(left,right+1):
if i%21==0:
print i,
㈣ Python编程的一个作业
simple...
谁可以帮帮我,第一次注册知道,没什么分, 但一定会去赚分追加给最好的答案
我就不信你还去赚分来给我~~O(∩_∩)O
def cycle(a,i = 0):
____i += 1
____if a == 1:
________return i
____if a % 2 == 1:
________return cycle(a*3 + 1,i)
____else:
________return cycle(a/2,i)
def myprint(a,b):
____starstr = ""
____for i in range(b):
________starstr += "*"
____mystr = str(a) + ":" + starstr
____print mystr
def main():
____i = input("Please Enter a Value for i:")
____j = input("Please Enter a Value for j:")
____for t in range(i,j+1):
________myprint(t,cycle(t))
main()
㈤ Python练习题
1
print("hi, “”“how are you”””, I’m fine and you")
2
a, b= map(int, input().split())
r=a//b
m=a%b
㈥ python网络编程作业
就目前来说python毕竟是一门脚本语言,很多企业不会直接招会Python的人。最多会说,招C++或者C#或者然后最后补上一句,熟悉python为佳!
㈦ python程序设计作业:查找1000以内的所有素数,保证每行输出10个,并求出这些素数的数量。(
摘要 Copyright © 1999-2020, CSDN.NET, All Rights Reserved
㈧ python 编程作业,达人进
第一题:
# -*- coding: cp936 -*-
def MToCAndCToM():
m=list("abcdefghijklmnopqrstuvwxyz")
c=list("qwertyikladcvbnmuhfxzosgjp")
mToC=dict(zip(m,c))
cToM=dict(zip(c,m))
result=""
inputNum=input("1.加密\n2.解密\n")
if inputNum==1:
string=raw_input("请输入要加密的明文:")
strList=list(string)
for s in strList:
result+=mToC[s]
print result
elif inputNum==2:
string=raw_input("请输入要解密的密文:")
strList=list(string)
for s in strList:
result+=cToM[s]
print result
else:
pass
while 1:
MToCAndCToM()
㈨ Python编程题怎么写
Python编程题写法:第一个问题使用排序算法,有很多种,可以使用简单一点的冒泡排序。第二个问题为了确保是输入了5个整数,可以使用while循环+try。
假设data.txt中所有的号码都在一行,没有换行,写入到data_asc.txt中时,假设每行一个,原文件中是否有换行;写入到data_asc.txt文件中时,是一行一个;还是所有的都在一行,然后用英文逗号隔开。
Python
是完全面向对象的语言。函数、模块、数字、字符串都是对象。并且完全支持继承、重载、派生、多继承,有益于增强源代码的复用性。Python支持重载运算符和动态类型。相对于Lisp这种传统的函数式编程语言,Python对函数式设计只提供了有限的支持。有两个标准库(functools, itertools)提供了Haskell和Standard ML中久经考验的函数式程序设计工具。
㈩ python面向对象编程作业
importre
classderivative:
def__init__(self,s):
self.s='+'+sifs[0]notin['+','-']elses
def__analysis__(self):
self.ite=list(re.finditer('[+-]',self.s))
self.items=[xforxinre.split(r'[+-]',self.s)ifx!='']
self.pm=[self.s[i.span()[0]]foriinself.ite]
self.var=[k[k.find('^')-1]forkinself.itemsifk.find('^')>-1][0]
self.ratio=[]
self.power=[]
foriteminself.items:
j=item.find('^')
k=item.find(self.var)
ifj>-1:
self.power.append(int(item[j+1]))
elifk>-1:
self.power.append(1)
else:
self.power.append(0)
foriteminself.items:
k=item.find('*')
ifk>-1:
self.ratio.append(int(item[k-1]))
elifitem.find(self.var)>-1:
self.ratio.append(1)
else:
self.ratio.append(int(item))
self.items=[t[1]fortinsorted(list(zip(self.power,self.items)),reverse=True)]
self.ratio=[t[1]fortinsorted(list(zip(self.power,self.ratio)),reverse=True)]
self.pm=[t[1]fortinsorted(list(zip(self.power,self.pm)),reverse=True)]
self.power.sort(reverse=True)
def__derivative__(self):
power=[x-1ifx>1else0forxinself.power]
ratio=[]
foriinrange(len(self.power)):
ifself.power[i]>1:
ratio.append(self.power[i]*self.ratio[i])
elifself.power[i]==1:
ratio.append(self.ratio[i])
else:
ratio.append(0)
items=[]
foriinrange(len(self.power)):
ifratio[i]==0:
continue
item=self.pm[i]
ifratio[i]>0:
item+=str(ratio[i])
ifpower[i]>0:
item+='*'+self.var
ifpower[i]>1:
item+='^'+str(power[i])
items.append(item)
self.out_s=''.join(items)
ifself.out_s[0]=='+':
self.out_s=self.out_s[1:]
defder(self):
self.__analysis__()
self.__derivative__()
returnself.out_s
s='2*x^3+3*x^2+5*x+1'
d=derivative(s)
print(d.der())
s='-5*x^6-3*x^3+12-4*x^4'
d=derivative(s)
print(d.der())
“不恰当的输入”不知道要处理什么级别的错误,所以没搞。自己根据需求去搞吧。