0% found this document useful (1 vote)
46 views

Test-1 - Python and Stat - Jupyter Notebook

This document contains solutions to 7 Python programming questions. Each question is numbered and includes the code to solve it. The questions cover topics like: 1) Finding unique numbers in a phone number. 2) Reversing a string. 3) Finding unique characters in a string. 4) Finding prime numbers between 1-100. 5) Appending a name to a file. 6) Retrieving keys and values from a dictionary. 7) Explaining lists and tuples with an example program and their differences.

Uploaded by

jeeshu048
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
46 views

Test-1 - Python and Stat - Jupyter Notebook

This document contains solutions to 7 Python programming questions. Each question is numbered and includes the code to solve it. The questions cover topics like: 1) Finding unique numbers in a phone number. 2) Reversing a string. 3) Finding unique characters in a string. 4) Finding prime numbers between 1-100. 5) Appending a name to a file. 6) Retrieving keys and values from a dictionary. 7) Explaining lists and tuples with an example program and their differences.

Uploaded by

jeeshu048
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

3/2/24, 11:53 AM test-1_python and stat - Jupyter Notebook

Find the number of unique numbers in your phone number and store it in one list

In [29]: #question no-1


n1=[7879522175]
n2=[]
for i in n1:
if i not in n2:
n2.append(i)
[7879522175]

String=” Hello world” reverse the given string.

In [2]: #question no-2


str1="Hello world"
ans=str1[::-1]
dlrow olleH

S=” ASjhdbgjhdbFYYJGJYTFJHGghdbhj%%6teyt894yt83yt87yt87ye”. find the unique values in the given string.

In [23]: #question no-3


S="ASjhdbgjhdbFYYJGJYTFJHGghdbhj%%6teyt894yt83yt87yt87ye"
s1=''
for i in S:
for i in 'aeiou':
if i not in s1:
s1=s1+i
print(s1)
aeiou

Get the prime numbers from 1 to 100 and store it in list

localhost:8888/notebooks/OneDrive/Documents/NARESHIT/PYTHON/test-1_python and stat.ipynb 1/3


3/2/24, 11:53 AM test-1_python and stat - Jupyter Notebook

In [27]: #question no-4


prime_numbers = []


for number in range(2, 101):
is_prime = True
for divisor in range(2, int(number**0.5) + 1):
if number % divisor == 0:
is_prime = False
break

if is_prime:
prime_numbers.append(number)

print("Prime numbers from 1 to 100:", prime numbers)
Prime numbers from 1 to 100: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 8
9, 97]

Create the file and append your name in the file

In [4]: #question no-5


file=[]
name='jeeshan hayat ali'
file.append(name)
Out[4]: ['jeeshan hayat ali']

Create the dictionary and get the values and keys in thar dictionary

In [17]: #question no-6


d1={'jeeshan':20,'ahmad':25}
keys=d1.keys()
values=d1.values()
print(keys,values)

dict_keys(['jeeshan', 'ahmad']) dict_values([20, 25])

Explain the list and tuple with one basic program. Explain the difference between them.

localhost:8888/notebooks/OneDrive/Documents/NARESHIT/PYTHON/test-1_python and stat.ipynb 2/3


3/2/24, 11:53 AM test-1_python and stat - Jupyter Notebook

In [ ]: my_list=[10,15,20,'a','b','c']
my tuple=(1,2,3,'a','b','c')

In [ ]: 1-Lists are mutable, meaning you can modify their elements (e.g., add, remove, or change values).
1-Tuples are immutable, so their elements cannot be modified after creation.

2-Lists use square brackets [],
2-tuples use parentheses ().

3-Lists can change in size (add or remove elements).

localhost:8888/notebooks/OneDrive/Documents/NARESHIT/PYTHON/test-1_python and stat.ipynb 3/3

You might also like