







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








print("Hi")
Hi
print("Hey There")
Hey There
print("Aman Narwar")
Aman Narwar
print(" ")
print(2+5)
print("2+5")
print(2.+5.)
x= type(x)
int
x=2. type(x)
float
x= type("x")
str
x=2. print(x)
NameError Traceback (most recent call last) /tmp/ipykernel_1273/2712581414.py in () ----> 1 x=a 2 print(x)
NameError: name 'a' is not defined
x=a print(x)
x="a" print(x)
a
1=a print(
print(2+3)
File "/tmp/ipykernel_7248/2896679607.py" line 1 print(2×3) ^ SyntaxError: invalid character '×' (U+00D7)
print(2×3)
elif (x!=2): print("Hug")
Smart
if x==3: print("Smart") elif (x!=2): print("Hug")
Hug
def F1(i=1,j=3): k=i+j return k
for i in range(1,2,5): print (i)
1
for i in range(1,5,2): print (i)
x= range(1,5,2) for i in x: print (i)
1 3
dtype(x)
NameError Traceback (most recent call last) /tmp/ipykernel_1903/2483919754.py in () ----> 1 dtype(x)
NameError: name 'dtype' is not defined
i= while i<5: print(i) i=i+
i= while i<5: print(i) i=i
Streaming output truncated to the la 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Factorial of 10 is 720 Factorial of 10 is 5040 Factorial of 10 is 40320 Factorial of 10 is 362880 Factorial of 10 is 3628800
n = int(input)
n= #fact = 1 for i in range (1,n+1): fact = fact*i print("Factorial of", n, "is", fact)
Factorial of 10 is 498282332576914445 Factorial of 10 is 996564665153828891 Factorial of 10 is 298969399546148667 Factorial of 10 is 119587759818459466 Factorial of 10 is 597938799092297334 Factorial of 10 is 358763279455378400 Factorial of 10 is 251134295618764880 Factorial of 10 is 200907436495011904 Factorial of 10 is 180816692845510714 Factorial of 10 is 180816692845510714
n= fact = 1. for i in range (1,n+1): fact = fact*i print("Factorial of", n, "is", fact)
Factorial of 10 is 1. Factorial of 10 is 2. Factorial of 10 is 6. Factorial of 10 is 24. Factorial of 10 is 120. Factorial of 10 is 720. Factorial of 10 is 5040. Factorial of 10 is 40320. Factorial of 10 is 362880. Factorial of 10 is 3628800.
n= #fact = 1. for i in range (1,n+1): fact = fact*i print("Factorial of", n, "is", fact)
Factorial of 10 is 1.734012131277275e Factorial of 10 is 3.46802426255455e+ Factorial of 10 is 1.040407278766365e
Added # before fact
Aman Narwar
No float in for loop
Aman Narwar
Factorial of 10 is 4.16162911506546e+ Factorial of 10 is 2.08081455753273e+ Factorial of 10 is 1.248488734519638e Factorial of 10 is 8.739421141637466e Factorial of 10 is 6.991536913309973e Factorial of 10 is 6. Factorial of 10 is 6.292383221978976e
n=int(input("10")) i=1. fact_ =i while(i<=n): fact_ *=i i=i+ print (fact_)
def factorial(n): if n<2: return 1 else: return n*factorial(n-1) x=int(input(10)) print(factorial(x))
NameError Traceback (most recent call last) /tmp/ipykernel_563/335881105.py in () 1 x= ----> 2 dtype(x) 3 x[1,2,3] 4 dtype(x) 5 x=(1,2,3)
NameError: name 'dtype' is not defined
x= dtype(x) x[1,2,3] dtype(x) x=(1,2,3) dtype(x)
x= type(x) x[1,2,3] type(x) x=(1,2,3)
TypeError: int object is not subscriptablex=[1,2,3,"A","B",10]
x print(x) x[3]
x print(x) x[-1]
[1, 2, 3, 'A', 'B', 10] 10
x print(x) x[::-1]
[1, 2, 3, 'A', 'B', 10] [10, 'B', 'A', 3, 2, 1]
x print(x) x[:-1]
[1, 2, 3, 'A', 'B', 10] [1, 2, 3, 'A', 'B']
x print(x) x[5:0:-1]
[1, 2, 3, 'A', 'B', 10] [10, 'B', 'A', 3, 2]
x print(x) x[3:5:1]
[1, 2, 3, 'A', 'B', 10] ['A', 'B']
S=[x**2 for x in range(10)] print(S)
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
S.append([x**2 for x in range (10,15,
print(S)
x= y=
print ("x=",y) print ("y=",x)
x= 15 y= 5
import math pi = math.pi result = pi** print ("pi^10 =", result)
pi^10 = 93648.
sum = 0 for i in range (1,101)
a=9. u= for t in range (1,101): v=u+a*t print ("at time t=",t,", velocity v=
at time t= 1 , velocity v= 9. at time t= 2 , velocity v= 19. at time t= 3 , velocity v= 29. at time t= 4 , velocity v= 39. at time t= 5 , velocity v= 49. at time t= 6 , velocity v= 58. at time t= 7 , velocity v= 68. at time t= 8 , velocity v= 78. at time t= 9 , velocity v= 88. at time t= 10 , velocity v= 98. at time t= 11 , velocity v= 107. at time t= 12 , velocity v= 117. at time t= 13 , velocity v= 127. at time t= 14 , velocity v= 137. at time t= 15 , velocity v= 147. at time t= 16 , velocity v= 156. at time t= 17 , velocity v= 166. at time t= 18 , velocity v= 176.
AttributeError Traceback (most recent call last) /tmp/ipykernel_4397/981816886.py in () 3 t=np.arange(0,101) 4 v=0+9.8*t ----> 5 np_v.to
AttributeError: 'numpy.ndarray' object has no attribute 'to'