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())
「不恰當的輸入」不知道要處理什麼級別的錯誤,所以沒搞。自己根據需求去搞吧。