正规python培训的优质

2018-08-28 记者节 阅读:

正规python培训的优质(共10篇)

正规python培训的优质(一)

Python,在一个图像中找最大的Y值并返回该值对应的X
Python
比如现在有一个一些点的Y值是【1,2,3,4,5,6】,他们分别对应X值为【0,1,2,3,4,5】,想用PHTHON中找出这些点中Y值最大的点并且返回给我该最大点对应的X值

y = [1, 2, 3, 4, 6, 7]
x = [2, 4, 6, 2, 6, 3]
print x[y.index(max(y))]

正规python培训的优质(二)

Write a program which asks the user for four numbers(Python)
1) Write a program which asks the user for four numbers and then tells them one of the following:
· That there were more even numbers than odd numbers
· That there were more odd numbers than even numbers
· That there were the same number of even and odd numbers
【正规python培训的优质】

evennum=0
oddnum=0
for i in range(0,4):
    num=input("please input a number:")
    if num%2==0:
        oddnum+=1
    else:
        evennum+=1
if evennum>oddnum:
    print "That there were more even numbers than odd numbers"
elif evennum<oddnum:
    print "That there were more odd numbers than even numbers"
else:
    print " That there were the same number of even and odd numbers"

正规python培训的优质(三)

请你帮我写下这行python的 语句的 注释
numLines = int(raw_input ("How many lines of stars do you want?"))
numStars = int(raw_input ("How many stars per line?"))
for line in range (0,numLines):
for star in range (0,numStars):
print "*",
print
求注释

numLines = int(raw_input ("How many lines of stars do you want?")) //屏幕提示:How many lines of stars do you want?并要求输入一个整数
numStars = int(raw_input ("How many stars per line?")) //屏幕提示:How many stars per line?并要求输入一个整数
for line in range (0,numLines)://for循环,line值从0递增到numLines的值,每次递增1
for star in range (0,numStars)://for循环,star值从0递增到numStars的值,每次递增1
print "*",//打印*
print//打印空行【正规python培训的优质】

正规python培训的优质(四)

python中 x=x[1:] 是什么意思

将x的第二位到最后一位的内容赋给x。
如 x = "abcdef"
x = x[1:]
print x
结果为:"bcdef"

正规python培训的优质(五)

python2.6中的os.path.walk() 对应 python3.2里哪个函数

os.walk

正规python培训的优质(六)

python:123 and 456
等于多少? 如何求的

Python中and是逻辑与,区别于&是位与

>>> 123 and 456
456

结果是456,这是因为and操作符等价于函数:

def and(a,b):
    if a:
       return b
    else:
       return a

正规python培训的优质(七)

python有exp和ln这样的数学函数没

math.exp() - 自然指数函数 e^x
math.sin() - 正弦函数 sin(x)
math.cos() - 余弦函数 cos(x)
math.e - 数学自然数 = 2.71828....

正规python培训的优质(八)

关于python的列表操作
一个列表a=[(2,4),(5,3),(6,3),(7,3)........]里面的元素是成对整数的,现在我想知道整数对中,后一个元素最多的那个是几,比如a中后一个元素分别是4,3,3,3最多的是3

def getm(a):
    dic={}
    for x,y in a:
            dic[y]=dic.get(y,0)+1            
    xdic={v:k for k,v in dic.items()}
    return xdic[max(xdic)]

if __name__=='__main__':
    print(getm([(2,4),(5,3),(6,3),(7,3)]))

正规python培训的优质(九)

Python中+=是什么意思

在while loops里我们常常会碰到的 +=
意思很简单,大致上大家都说了
再加以解释吧!
>>> num = 1
当 num 小过5 或等于 5 它会一直不断的输出,直到 num 大过才会停止输出"I"m Mtcy"
在这个时候我们注意到在下方有一行代码.num +=1
在这儿的意思是 num = num + 1
在while里面我们必须输入这一行代码,为什么?
因为,如果我们不输入这一行代码,那么 num 永远都会等于 1
永远等于1的话,那么就会不断的输出 "I"m Mtcy",那么唯一能做的就只有强制性关闭.
如果加上 num += 1 那么每次执行完一次代码,num都会加1
>>> while (num

正规python培训的优质(十)

求python高手解决.
Write a python program that letsthe user enter the loan amount and loan period in number of years.The program will then display the monthly andtotal payments for each monthly interest rate starting from 4 to 8 inincrements of 1.Calculate the valuesand print the table displaying the interest rate in the first column,themonthly payment in the second column,and the total payment in the thirdcolumn.
Your program should not allow theuser to enter negative amounts for either of the input numbers.Write a function getPositiveFloat that takes a string to be printed at the inputprompt and returns a positive float.getPositiveFloat should loop until it isgiven a positive number and display “Please provide a positive number.” andreprint the prompt anytime the user enters a negative number.Use getPositiveFloat in your main function,for all of yourinput needs
Write a separate function calcMonthly that takes in a rate,anamount and a length of the loan as arguments and returns the monthly payment.
Write a separate function printPayments that calls calcMonthly as part of a loop thatprints the table.
最后的input会变成这样.
Enter the amount(greater than 0) of the loan 10000
Enter the number of years of the loan 5
Rate MonthlyPayment Total Payment
4% $442.02 $26521.11
5% $528.28 $31696.91
6% $618.76 $37125.43
7% $712.29 $42737.54
8% $807.98 $48478.77
Do you want to create another table?
(Enter y for Yes n for No):y

输入贷款总量和贷款年数,显示每个月的还款数额和总还款数额
不是很理解"for each monthly interst rate starting from 4 to 8 in increments of 1",请解释
先粘出来写了开头的代码:
import os
class LOAN_ERROR(Exception):
def __init__(self, message):
self._message = message
def __str__(self):
return self._message
if __name__ == "__main__":
try:
total_loan_money = raw_input("loan amount: ")
loan_period = raw_input("loan period (year): ")

if not isinstance(loan_period, int) or loan_period < 0:
raise LOAN_ERROR("Please provide a positive number.")

正规python培训的优质

http://m.zhuodaoren.com/jieri851633/

推荐访问:

记者节推荐文章

推荐内容

上一篇:2018山东普通话成绩查询 下一篇:2018山东普通话考试