40923225 cp2020

  • Home
    • Site Map
    • reveal
    • blog
  • Homework1(作業1)
    • PCH10.Networking Hardware(網路硬件)
      • Network Devices(網路設備)
      • Install a Network Adaper(安裝網路適配器)
    • PCH13.IPv4 and IPv6 Addresses(IPv4和IPv6的地址)
      • IPv4 and IPv6 Addresses(IPv4和IPv6的地址)
      • IPv4 Addressing(IPv4編址)
      • IPv4 Address Classes(IPv4網址類別)
      • Assigning an IP Address(分配IP網址)
      • IPv6
      • Classful Vs. Classless Addressing.Subnet and CIDR(相對於無類尋址.子網和CIDR)
      • Windows Networking(Windows網絡)
  • W8 cp2020
  • Homework2(作業2)
    • 2-1(分組)
  • Homework3(作業3)
    • Check Primality Functions (檢查功能)11
    • Divisors(除數)4
    • File Overlap Solutions(文件重疊)23
Check Primality Functions (檢查功能)11 << Previous Next >> File Overlap Solutions(文件重疊)23

Divisors(除數)4

The topics that you need for this exercise combine lists, conditionals, and user input. There is a new concept of creating lists.There is an easy way to programmatically create lists of numbers in Python.

(本練習需要的主題包括列表,條件和用戶輸入。有一個創建列表的新概念。有一種簡便的方法可以在Python中以編程方式創建數字列表。)

To create a list of numbers from 2 to 10, just use the following code:

  x = range(2, 11)

Then the variable x will contain the list [2, 3, 4, 5, 6, 7, 8, 9, 10]. Note that the second number in the range() function is not included in the original list.

Now that x is a list of numbers, the same for loop can be used with the list:

for elem in x:

print elem

Will yield the result:

2.3.4.5.6.7.8.9.10

Exercise 4(練習4)

Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (創建一個程序,詢問用戶一個數字,然後打印出該數字的所有除數的列表。)

solution(解答)

num=int(input("Enter the number you want to divide: "))
listRange=list(range(1,num+1))
divisorList=[]
for number in listRange:
if num % number == 0:
divisorList.append(number)
print(divisorList)


Check Primality Functions (檢查功能)11 << Previous Next >> File Overlap Solutions(文件重疊)23

Copyright © All rights reserved | This template is made with by Colorlib