Python Basics Assignment 1

Python Basics Assignment


#Q1.

n = int(input('put the value the of n :'))

r = float(input('put the value the of r :'))

p = float(input('put the value the of p :'))


print('value of n : ',n)

print('value of r : ',r)

print('value of p : ',p)


A = p * (1 + r / 100) ** n


print('value of A = ',A)


#Q2.

A = int(input('put the value the of A :'))

B = int(input('put the value the of A :'))


print('value of n : ',A)

print('value of r : ',B)


Str = f"There are {A} students in the class, with {B} who play at least one sport."

print(Str)



##or##


print(f"There are {A} students in the class, with {B} who play at least one sport.")


#Q3.

sample= "It goes without saying, \"Time is Money\", and none can deny it."

print(sample)


#Q4.
import math
x = lambda a,b: a//b
x(10,3)


#Q5.
a = int(input('input the value of a : '))
b = int(input('input the value of b : '))

print('a =',a)
print('b =',b)
if a > b:
    print("a is greater than b : ", a,'>',b)
elif a < b:
    print("b is greater than a : ", a,'<',b)
else:
    print("a and b are equal : ", a,'=',b)  


#Q6.

#import os
#import numpy as np
#my_list1=[2,7,3,5,4,6]
#print(my_list1)
#arr_1 = numpy.array(my_list1,dtype = int)
#print(arr_1)

#upper code give us error bocz "name 'numpy' is not defined" plz use 'np' inside of 'numpy'

#Correct code below


import os
import numpy as np
my_list1=[2,7,3,5,4,6]
print(my_list1)
arr_1 = np.array(my_list1,dtype = int)
print(arr_1)


#Q7.
str = "Machine Learning"
print(str)
substring = str[8:13]
print(substring)


#Q8.
a = list(range(10,26,4))
print(a) 
b = a.index(18)
print(b)




numbers = list(range(10,26,4))
print('numbers :' ,numbers)
find_the_number_index = 18 

print(' number is : ',find_the_number_index)
index_is = numbers.index(find_the_number_index)
print("The index of", find_the_number_index, "is", index_is)


#Q10.
A Python NameError exception is raised when: -

ans. a. Trying to access a variable which has not been defined


#Q9.
import math

a = int(input('input the value of a : '))
b = int(input('input the value of b : '))

print('a =',a)
print('b =',b)

num1 = a**b
num2 =pow(a,b)

print('num1 =',num1 )
print('num2 =',num2 )

if num1 == num2:
    print('both are equal ', num1,'=',num2)
else:
    print('both are not equal ', num1,'not equal',num2) 

Q12.
FileNotFoundError exception is raised by operating system errors when: -
a. Trying to create a file or directory which already exists
b. A file or directory is requested but does not exist in the working directory
c. Trying to run an operation without the adequate access rights
d. A directory operation, os.listdir() is requested on something which is not a
directory

ans: b. A file or directory is requested but does not exist in the working directory

Q13.
Consider a variable Z. The value of Z is "ID-5632". Data type of Z is: -
a. Complex
b. Character
c. Integer
d. Boolean

ans: b. Character


Q14.
Which of the following variable(s) are character data type?
a. K= “4”
b. J= “Welcome”
c. L= “?”
d. All of the above

ans:d. All of the above




Q15. Choose the symbol/s that does not have the ability to convert any values to string?

ans. d. # 


#Q16.
Country = {
    'India': 'Delhi',
    'China': 'Beijing',
    'Japan': 'Tokyo',
    'Qatar': 'Doha',
    'France': 'Marseilles'
}

print(Country)

Country['France'] = 'Paris'

print(Country)




#Q17.
tuple_1 = (1,5,6,7,8)
tuple_2 = (8,9,4)

print(sum(tuple_1))
print(len(tuple_2))
print(tuple_2 + tuple_1)
tuple_1[3] = 45 # it's give 'TypeError: 'tuple' object does not support item assignment'

#tuples are immutable  

#Q18.
s={1,2,3,4,4,4,5,6}
print(s)
Total_count = len(s)
print("Number of elements =", Total_count)


#because it is a set, set does not contain repeated value


#Q19
def pythagorean_triplets(N):
    triplets = []
    for a in range(1, N+1):
        for b in range(a, N+1):
            c_squared = a**2 + b**2
            c = int(c_squared**0.5)
            if c_squared == c**2 and c <= N:
                triplets.append((a, b, c))
    return triplets

N = int(input("Enter the value of N = "))

triplets = pythagorean_triplets(N)
print("Pythagorean triplets with sides no greater than", N, "are =")
for triplet in triplets:
    print(triplet)









Comments

Popular posts from this blog

SQL Assignment – Module 4

SQL Assignments TABLE

SQL Assignment – Module 1