CS 2 Ans - Introduction To Python
CS 2 Ans - Introduction To Python
CS 2 Ans - Introduction To Python
def list_count_4(nums):
count = 0
for num in nums:
if num == 4:
count = count + 1
return count
print(list_count_4([1, 4, 6, 7, 4]))
print(list_count_4([1, 4, 6, 4, 7, 4]))
def is_vowel(char):
all_vowels = 'aeiou'
return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))
histogram([2, 3, 6, 5])
6 Write a Python program that will accept the base and height of a triangle
and compute the area.
area = b*h/2
print(sum(2, 1, 2))
print(sum(3, 2, 2))
print(sum(2, 2, 2))
print(sum(1, 2, 3))
print(sum(5, 4, 3))
8. Write a Python program to sum of two given integers. However, if the sum
is between 15 to 20 it will return 20.
print(sum(10, 6))
print(sum(10, 2))
print(sum(10, 12))
9. Write a Python program that will return true if the two given integer values
are equal or their sum or difference is 5.
print(test_number5(7, 2))
print(test_number5(3, 2))
print(test_number5(2, 2))
10. Write a Python program to compute the distance between the points (x1,
y1) and (x2, y2).
import math
p1 = [4, 0]
p2 = [6, 6]
distance = math.sqrt( ((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2) )
print(distance)