无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

加拿大瑞爾森大學(xué) Python習(xí)題 Lab 1

2023-08-05 08:53 作者:逃跑的叮當(dāng)貓  | 我要投稿

前段時(shí)間教家里的少爺學(xué)python,做了他們大學(xué)的習(xí)題,基本上做完這8章習(xí)題也就學(xué)會(huì)python了,現(xiàn)在分享給大家,有興趣的同學(xué)自取。測(cè)試采用Spyder IDE?

Python 3.8.10 64-bit | Qt 5.15.2 | PyQt5 5.15.7 | Windows 10?


Lab 1 – CPS 106?

This lab gives you more practice using basic elements of python. The following are based on exercises from the book: Introduction to Computation and Programming Using Python, by John Guttag.?

1. Write a program that examines three variables x , y , and z, and prints the largest odd number among them. If none of them are odd, it should print a message to that effect.?

Test you program on the inputs:?

x = 234, y = 653, z = 34,?

x = 56, y = 776, z = 787,?

x = 79, y = 87465, z = 764563?

Hint: this is done using nested if/else statements.?

2. Write a program that asks the user to input 10 integers, and then prints the largest odd number that was entered. If no odd number was entered, it should print a message to that effect. This is a more general version of Question 1. For example of the integers were: 10, 9, 7, 12, 2, 5, 15, 100, 90, 60, then the program would print 15 as the largest odd number.?

Hint: use a while or for loop to ask the user for a number in each iteration.?

3. Write a program that adds the amounts of money in a list. An example input is: 23 CAD, 345 CAD, 55 CAD. The output for this input is 423 CAD.?

Test you program on the inputs:?

527 CAD, 392 CAD, 477 CAD, 495 CAD, 569 CAD, 380 CAD, 38 CAD, 19 CAD, 473 CAD, 31 CAD 478 CAD, 538 CAD, 614 CAD, 987 CAD, 632 CAD, 525 CAD, 955 CAD, 322 CAD, 357 CAD, 526 CAD?

Hint: you can use the split function with the separator ‘ ‘ on the input as was done in the class. The resulting list will also contain non-numeric values like “CAD,”. The string object has a function called isnumeric() that checks if a string is a number. For example, if s = “123” then s.isnumeric() return True, but if s = “yuew” the s.isnumeric() return False.

答案

習(xí)題1-2 find largest odd

# -*- coding: utf-8 -*-

"""

Created on Fri Jan? 6 18:07:18 2023


@author: pc

"""


? ??

def find_largest_odd(numbers):

? ? largest_odd = None

??

? ? for number in numbers:

? ? ? ? if number % 2 == 1:

? ? ? ? ? ? if largest_odd is None or number > largest_odd:

? ? ? ? ? ? ? ? largest_odd = number


? ? if largest_odd is not None:

? ? ? ? print(largest_odd)

? ? else:

? ? ? ?print("There are no odd numbers.")


numbers1 = [10, 9, 7, 12, 2, 5, 15, 100, 90, 60]

find_largest_odd(numbers1)


習(xí)題 1-3-1 amounts

# -*- coding: utf-8 -*-

"""

Created on Sat Jan? 7 10:00:30 2023


@author: pc

"""


def find_largest(numbers):

? largest = 0

??

? for number in numbers:

? ? ? largest += int(number.split()[0])

? ? ? #print(int(number.split()[0]))



? if largest != 0:

? ? print(largest, 'CAD')

? else:

? ? print("There are 0.")


A = ['10 cad', '9 cad', '7 cad', '12 cad' , '2 cad', '5 cad', '15 cad', '100 cad','17 cad','90 cad', '60 cad', '10 cad']

find_largest(A)


#? ? ? print(number.split()[0])


習(xí)題 1-3-2 split

# -*- coding: utf-8 -*-

"""

Created on Sat Jan? 7 09:40:34 2023


@author: pc

"""



money=input().split(', ')

total={}


for i in money:

? ? j=i.split()

? ? if total.get(j[1],0)==0:

? ? ? ? total[j[1]]=int(j[0])

? ? else:

? ? ? ? total[j[1]]+=int(j[0])

? ? ? ??

? ? ? ??

for i in total:

? ? print(total[i],i)



加拿大瑞爾森大學(xué) Python習(xí)題 Lab 1的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
醴陵市| 台北市| 沁水县| 云霄县| 沅江市| 齐齐哈尔市| 慈利县| 永泰县| 泽州县| 吉木乃县| 淮北市| 玉门市| 泰兴市| 炉霍县| 鄂伦春自治旗| 阿勒泰市| 青川县| 白城市| 监利县| 个旧市| 隆尧县| 平阳县| 宜春市| 金堂县| 壤塘县| 独山县| 兰州市| 普洱| 襄汾县| 临湘市| 昆明市| 通辽市| 抚顺市| 浦东新区| 淮安市| 宝山区| 靖安县| 富阳市| 绍兴县| 闽清县| 丰城市|