You are on page 1of 3

Assignment 1

Name: Divesh Tadimeti

Roll No: SYAIMLA63

a) Write a python program to create a list of random numbers in normal distribution and display
the frequency of each value

# list of random number from normal distribution and its frequency


import random
from collections import Counter #Counter is a class

start = 0
end = 1
num_values = 20

random_numbers = [random.uniform(start, end) for _ in range(num_values)]

random_numbers = [round(num, 2) for num in random_numbers] #round will round off number

frequency_counter = Counter(random_numbers)

print("Value \tFrequency")
print("------------------")
for value, frequency in frequency_counter.items():
print(f"{value}\t{frequency}")

Value Frequency
------------------
0.46 2
0.54 1
0.32 1
0.05 2
0.85 2
0.95 1
0.34 1
0.13 2
0.68 1
0.42 1
0.83 1
0.31 1
0.69 1
0.89 1
0.09 1
0.21 1

b) Write a python program to print the odd and even numbers from a given range taken as per
user's input and display the prime numbers from the first 20 odd numbers.

#Identify wheter number is even, odd or prime

def check_prime(n):
divisors = 0
for i in range(1, int((n + 1) / 2) + 1):
if n % i == 0:
divisors += 1

return divisors < 2

start = int(input("Enter the lower limit:"))


end = int(input("Enter the upper limit:"))

even, odd, prime = [], [], [] # Takes Multiple List as an input

for i in range(start,end):
if i % 2 == 0:
even.append(i)
else:
odd.append(i)

if check_prime(i) and len(prime) < end:


prime.append(i)

print("List of even numbers from ", start, " to", end, " : ", even)
print("List of Odd Numbers from ", start, " to", end, " : ", odd)
print("List of First ", end ," Prime numbers from ", start, " to", end, " : ", prime)

Enter the lower limit:1


Enter the upper limit:10
List of even numbers from 1 to 10 : [2, 4, 6, 8]
List of Odd Numbers from 1 to 10 : [1, 3, 5, 7, 9]
List of First 10 Prime numbers from 1 to 10 : [1, 2, 3, 5, 7]

c) Write a python program to read any .csv file as per user-provided input and display its
content.

import pandas as pd #Here, <previous_name> as <alias_name>; 'as' keyword used to give a


df = pd.read_csv("Data_Africa.csv") #First upload 'Data_Africa.csv' or any csv file to:
df # here df is just a variable, it means df = data frame
ID Year Country Continent Population GDP (USD)

0 1 2000 Uganda East Africa 23303189 6.193247e+09

1 2 2001 Uganda East Africa 24022603 5.840504e+09

You might also like