### Added last two solutions of the exercises

parent e8c30efb
For_Ex_3.py 0 → 100644
 """Calculate sum of odd and even numbers in a list in python """ numList = [] #create an empty list for entering numbers evenSum = 0 #declare and initialise a variable as evenSum=0 oddSum = 0 #declare and initialise a variable as oddSum=0 num = int(input("Enter the number of list elements: ")) for i in range (1, num + 1): value = int(input("Please enter the value %d: " %i)) numList.append(value) j = 0 while (j
For_Ex_4.py 0 → 100644
 """Write a program that simulates tossing a coin n times and print how many times the tails and the head appeared. """ from random import randint n = int(input("Input the desired number: ")) num_tails = 0 num_heads = 0 for i in range(n): toss = randint(0, 1) if toss == 0: num_tails = num_tails + 1 else: num_heads = num_heads + 1 tails_prob = num_tails / n * 100 heads_prob = num_heads / n * 100 print("Probability of tails: ", tails_prob, "%") print("Probability of heads: ", heads_prob, "%") \ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!