0% found this document useful (0 votes)
3 views

Python NMFS

The document contains a series of Python code snippets demonstrating various programming tasks, including a simple calculator, counting vowels in a string, finding the largest of three numbers, checking for prime numbers, calculating factorials, palindrome checking, pattern drawing, creating a database, exporting data to CSV, and reading a CSV file into a DataFrame. Each section provides a brief description of the task along with the corresponding code. These examples serve as practical applications of Python programming concepts.

Uploaded by

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

Python NMFS

The document contains a series of Python code snippets demonstrating various programming tasks, including a simple calculator, counting vowels in a string, finding the largest of three numbers, checking for prime numbers, calculating factorials, palindrome checking, pattern drawing, creating a database, exporting data to CSV, and reading a CSV file into a DataFrame. Each section provides a brief description of the task along with the corresponding code. These examples serve as practical applications of Python programming concepts.

Uploaded by

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

Python

1.Simple Calculator

a = float(input("Enter first number: "))


b = float(input("Enter second number: "))
op = input("Enter operation (+, -, *, /): ")

if op == '+':
print("Result:", a + b)
elif op == '-':
print("Result:", a - b)
elif op == '*':
print("Result:", a * b)
elif op == '/':
print("Result:", a / b)
else:
print("Invalid operator")

2.Count Vowels in a String

text = input("Enter a string: ")


vowels = "aeiouAEIOU"
count = sum(1 for ch in text if ch in vowels)
print("Number of vowels:", count)
Python

3.Find the Largest of Three Numbers


a = int(input("Enter first: "))
b = int(input("Enter second: "))
c = int(input("Enter third: "))
print("Largest is:", max(a, b, c))

4. Check Prime Number

num = int(input("Enter a number: "))


if num > 1:
for i in range(2, num):
if num % i == 0:
print("Not a Prime Number")
break
else:
print("Prime Number")
else:
print("Not a Prime Number")
Python

5.Factorial of a Number

num = int(input("Enter a number: "))


fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial:", fact)

6. Palindrome Checker

text = input("Enter a word: ")


if text == text[::-1]:
print("Palindrome")
else:
print("Not a Palindrome")
Python

7.Pattern Drawing
Draw these ?
*
**
***
****
*****
Code:
for i in range(1,6):
for j in range(i):
print("*",end=" ")
print()

8. Create a database named


"mydatabase" Using Python
import mysql.connector

mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")


Python

9. Export Data to CSV using pandas


Name=['Alice', 'Bob']
Age=[25, 30]
import pandas as pd

data = {
'Name': ['Alice', 'Bob'],
'Age': [25, 30]
}
df = pd.DataFrame(data)
df.to_csv('output.csv', index=False)

10.Read “data.csv” and convert it into


DataFrame Get Basic Information About
DataFrame
import pandas as pd

df = pd.read_csv('data.csv')
print(df.info())
print(df.describe())
Python

You might also like