0% found this document useful (0 votes)
3 views6 pages

PPS Code Questions

Uploaded by

amaan.m.0407
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)
3 views6 pages

PPS Code Questions

Uploaded by

amaan.m.0407
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

PPS Program Questions with Answers

1. Write Program in python to find whether the given number is an Amstrong


number
or not.
A
N
S

Program:
print(" Enter a number to check if it is an armstrong number or not")
num=int(input("Enter a number: ") )

arm=0
temp=num
while temp>0:
digit=temp%10
arm+=digit**3
temp//=10
if num==arm:
print(num,"is an armstrong number")
else:
print(num,"is not an armstrong number")

Output:

Enter a number to check if it is an armstrong number or not


Enter a number 153
153 is an armstrong number

2. Write Program in python to concatenate two strings using + operator.


Here‘s a simple Python program to concatenate two strings using the + operator:

# Program to concatenate two strings using + operator


# Input from user

str1 = input("Enter first string: ")


str2 = input("Enter second string: ")

# Concatenation using +
result = str1 + str2

# Display result
print("Concatenated string:", result)
■ Example Run
Input:
Enter first string: Hello
Enter second string: World
Output:
Concatenated string: HelloWorld

3. Write Program in python to reverse a string using user defined function.


# Program to reverse a string using user -defined function

def reverse_string(s):
# Using slicing to reverse the string
return s[:: -1]

# Input from user


text = input("Enter a string: ")

# Call the function


reversed_text = reverse_string(text)

# Display result
print("Reversed string:", reversed_text)
■ Example Run
Input:
Enter a string: Python
Output:
Reversed string: nohtyP

4. Write a program to test whether a number entered by user is positive,


negative or zero.
num = int(input("Enter a number: "))
if num > 0:
print("The number is Positive")
elif num < 0:
print("The number is Negative")
else:
print("The number is Zero")

Output:
Enter a number: 8
The number is Positive

5. Write a program to print the multiplication table of a number up to a given


range.
n = int(input("Enter a number: "))
for i in range(1, 11):
print(n, "x", i, "=", n * i)

output:
Enter a number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

6. Develop a program to print the absolute path of a file using OS. path. join.
import os
# Define directory and filename
directory = "C: \\Users \\Public \\Documents"
filename = "[Link]"

# Join directory and filename into a full path


file_path = [Link](directory, filename)

# Get absolute path


absolute_path = [Link](file_path)

# Print result
print("Absolute path of the file:", absolute_path)

7. Implement a program to append data to an already existing file.


Once you have created the file you can always open the file to write more data or
append data to the file.
• When you open the file in append mode file pointer is set to end of the file, so that
existing data will be kept as it is.
• To append data you must open the file in append mode „a■.
• Note that if you have opened file in write („w■) mode existing data will be erased and
new data i s added from starting of the file.
• Python program to append data to the file:

fileobj=open("[Link]","a")
[Link](" \nHello world \nWelcome to Python \n")
[Link]()
print("Data appended to the file..")

Output:
Data appended to the file..

If you open the file in append mode and if the file is not exist then new file is created and
data writing will begin from start.

8. python programming languages.


1. Web Development :
Python is widely used to build robust and scalable web applications using frameworks like
Django, Flask, and FastAPI. These frameworks simplify development by providing tools for
database interaction, routing, and security. Python‘s versatility allows deve lopers to create
anything from personal blogs to enterprise -level websites.

9. python programming language and list different software’s


developed in python.
brief history of python programming :

■ Python is created by Guido Van Rossum in the 1980s.


■ Rossum published the first version of Python code (0.9.0) in February 1991 at the CWI
(Centrum Wiskunde & Informatics) in the Netherlands , Amsterdam.
■ Python is derived from ABC programmin g language, which is a general -purpose
programming language that had been developed at the CWI.
■ Rossum chose the name "Python", since he was a big fan of Monty Python's Flying Circus.
■ Python is now maintained by a core development team at the institute, a lthough Rossum
still holds a vital role in directing its progress.

Following list of different Software developed in python:


■ Netflix
■ Meta / Facebook
■ Amazon
■ Dropbox
■ Original
■ Uber
■ Pinterest
■ Quora
10. Python program to concatenate two strings using the + operator:
# Program to concatenate two strings using + operator
# Input from user

str1 = input("Enter first string: ")


str2 = input("Enter second string: ")

# Concatenation using +
result = str1 + str2

# Display result
print("Concatenated string:", result)
■ Example Run
Input:
Enter first string: Hello
Enter second string: World
Output:
Concatenated string: HelloWorld

11. Python program to append data to the file:


fileobj=open("[Link]","a")
[Link](" \nHello world \nWelcome to Python \n")
[Link]()
print("Data appended to the file..")

Output:
Data appended to the file..

If you open the file in append mode and if the file is not exist then new file is created and
data writing will begin from start.

12. Python programming Language.

13. Python programming is clearly defined and easily readable .

14. python programming languages.

15. python program.


■ Tuple is a data structure supported by python.
■ A tuple is a sequence of immutable objects. That means you cannot change the
values in a tuple.
■ Tuples use parentheses to define its elements.

Python Program Using Tuple:


# Creating a tuple
Eg.
fruits = ("Apple", "Banana", "Mango", "Orange")
print(fruits)
Output:
('Apple', 'Banana', 'Mango', 'Orange')

# Displaying the tuple


print("Tuple elements are:", fruits)
Output:
Tuple elements are: ('Apple', 'Banana', 'Mango', 'Orange')

# Accessing elements
print("First element:", fruits[0])
Output:
First element: Apple

# Length of tuple
print("Number of elements:", len(fruits))
Output:
Number of elements: 4
# Iterating through tuple
for item in fruits:
print(item)
Output:
Apple
Banana
Mango
Orange

16. python program that counts the number of vowels and consonants in a
given
string using iteration.

# Program to count vowels and consonants in a string

# Input from user


text = input("Enter a string: ")

# Convert string to lowercase


text = [Link]()

# Initialize counters
vowels = 0
consonants = 0

# Iterate through each character


for ch in text:
if [Link](): # Check if character is an alphabet
if ch in "aeiou":
vowels += 1
else:
consonants += 1

# Display results
print("Number of vowe ls:", vowels)
print("Number of consonants:", consonants)

Output:
Enter a string: python
Number of vowels: 1
Number of consonants: 5

17. python program using import statement.


■ For example, to create a package MyPackage, create directory called MyPackage
having module MyModule and __init__.py file.

File Name: [Link]


def display():
print("Hello")
str = "Welcome to World of Python"

Now, to use MyModule in a program, import it in any one of the two ways:
import [Link] e
or
from MyPackage import MyModule
18. python program to create a class Employee with the attributes Name, emp
_id,
and salary and display data of 2 employees.

class Employee:

# Constructor
def __init__(self, name, emp_id, salary):
[Link] = name
self.emp_id = emp_id
[Link] = salary

# Method to display employee details


def display(self):
print("Employee Name :", [Link])
print("Employee ID :", self.emp_id)
print("Salary :", [Link])
print(" --------------------------- ")

# Creating objects for 2 employees


e1 = Employee("Rahul", 101, 50000)
e2 = Employee(" Neha", 102, 60000)

# Displaying employee details


[Link]()
[Link]()

Output:
Employee Name : Rahul
Employee ID : 101
Salary : 50000
---------------------------
Employee Name : Neha
Employee ID : 102
Salary : 60000
---------------------------

You might also like