Skip to content

Commit 1772b91

Browse files
authored
Add files via upload
1 parent c181594 commit 1772b91

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CheckPrimalityFunctions.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Ask the user for a number and
2+
# determine whether the number is prime or not.
3+
4+
def get_num():
5+
number = input("What number would you like to determine the primality of?\n")
6+
while(not number.isdigit()):
7+
number = input("Please provide a number to determine the primality of?\n")
8+
return int(number)
9+
10+
def check_divisible(num):
11+
for x in range(2, num-1):
12+
if num % x == 0:
13+
return x
14+
return 0
15+
16+
number = get_num()
17+
isdivisible = check_divisible(number)
18+
19+
if(not isdivisible):
20+
print(str(number) + " is prime.")
21+
if(isdivisible):
22+
print(str(number) + " is not prime. The first divisor for it (other than 1) is " + str(isdivisible) + ".")

ListEnds.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Write a program that takes a list of numbers, for example:
2+
# a = [5, 10, 15, 20, 25]
3+
# and makes a new list of only the first and last elements
4+
# of the given list. For practice, write this code inside a function.
5+
6+
def list_ends(mylist):
7+
return [mylist[0], mylist[len(mylist)-1]]
8+
9+
a = [5, 10, 15, 20, 25]
10+
11+
print(list_ends(a))

0 commit comments

Comments
 (0)