0% found this document useful (0 votes)
20 views2 pages

Python Practical Programming Tasks

The document contains practical Python programming questions and their corresponding answers. It covers topics such as basic arithmetic operations, checking even/odd numbers, calculating factorials, determining prime numbers, generating Fibonacci series, checking palindromes, and reversing numbers. Additionally, it includes error identification and string manipulation examples.

Uploaded by

bruhplsbra
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 (0 votes)
20 views2 pages

Python Practical Programming Tasks

The document contains practical Python programming questions and their corresponding answers. It covers topics such as basic arithmetic operations, checking even/odd numbers, calculating factorials, determining prime numbers, generating Fibonacci series, checking palindromes, and reversing numbers. Additionally, it includes error identification and string manipulation examples.

Uploaded by

bruhplsbra
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

Python Practical Questions

Q1. Write a program to input two numbers and print their sum.
Ans: a=int(input('Enter first: ')); b=int(input('Enter second: ')); print('Sum=',a+b)
Q2. Write a program to check even or odd number.
Ans: n=int(input('Enter: ')); print('Even' if n%2==0 else 'Odd')
Q3. Write program for factorial.
Ans: n=int(input('Enter: ')); f=1 for i in range(1,n+1): f*=i print('Factorial=',f)
Q4. Write program to check prime number.
Ans: n=int(input('Enter: ')); flag=True for i in range(2,n): if n%i==0: flag=False; break
print('Prime' if flag else 'Not Prime')
Q5. Write program to display Fibonacci series up to n terms.
Ans: n=int(input('Enter terms: ')); a,b=0,1 for i in range(n): print(a,end=' '); a,b=b,a+b
Q6. Write program to check palindrome string.
Ans: s=input('Enter string: ') print('Palindrome' if s==s[::-1] else 'Not Palindrome')
Q7. Predict output: print('Python'*3)
Ans: Ans: PythonPythonPython
Q8. Find error: if a=5: print(a)
Ans: Ans: Error → assignment not allowed in if condition, should be 'if a==5:'
Q9. Write program to reverse a number.
Ans: n=int(input('Enter: ')); rev=0 while n>0: rev=rev*10+n%10; n//=10 print('Reverse=',rev)
Q10. Write program to calculate sum of digits of number.
Ans: n=int(input('Enter: ')); s=0 while n>0: s+=n%10; n//=10 print('Sum of digits=',s)
bsdk jeele apni jindagi

You might also like