1. Trang chủ
  2. » Tất cả

AP computer science principles 2020 pilot: create task student sample i

1 2 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 1
Dung lượng 48,95 KB

Nội dung

AP Computer Science Principles 2020 Pilot Create Task Student Sample I AP Computer Science Principles 2020 Create Task Student Sample I 3 )a ) The video shows the program being used to calculate rando[.]

CSP 2020 Sample I AP Computer Science Principles: 2020 Create Task Student Sample I 3.)a.) The video shows the program being used to calculate random integers based on an integer input This address the issue of having to calculate random numbers for various purposes Now there is an easy tool to this b.) def genlist(n): list = [] for i in range(n): r = random.randint(0,10) if n < 2: r += list.append(r) Segment 2: print(genlist(x)) The data contained in the “list” represents random integers It makes generating multiple numbers easier because without lists each number would need to be printed individually The list is initialized on the second line and elements are added to the list on the last line c.) Segment 1: def genlist(n): list = [] for i in range(n): r = random.randint(0,10) if n < 2: r += list.append(r) return list Segment 2: print(genlist(x)) This procedure consolidates the generation of random numbers into a simple function This accomplishes its task by generating numbers and returning a list This is the list that the program needs to print d.) One case was inputting the number and the other was inputting 10 During one only numbers are generated and the other 10 are generated The expected result is a list with a.) random ints b.) 10 random ints

Ngày đăng: 22/11/2022, 19:39

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN