Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions 54ntu/AtmMachine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#todos
# set default values for pin
# define gloabl variable for total_balance, attempts=3
#take the pin
#coampare it
#count the attempts
#if attempt is more than three then block that account

#if pin is ok then display the menus i.e. withdraw, deposit, inquiry and exit
#if selected withdraw then ask the user to enter the amount
# check whther the amount is sufficient or not
# if not sufficient then display the msg and go to main menu
#if sufficient amount then decrease the amount from total_balance
#print the remaining amount and go to main menu
# if deposit is selected then
# ask the user to enter the amount
#then add the amount to the total_balance
# print the total balance amount and go to the main menu
#if inquiry then display the balance amount
# if exit then just exit the main menu



total_balance = 0
pin = 1234
attempts = 3

def ATM():
global attempts # here we declared attempts as global because if we want to modify the value of gloabl variables in python then we need to redeclare that variable as global inside the function
if(attempts <=3 and attempts >0):
userPin = int(input("enter your pin : "))
if(userPin ==pin):
print("1. Withdraw 2.Deposit \n 3.Inquiry 4.Exit")

userchoice = int(input("select your choice 1,2,3,4 : "))
if(userchoice == 1):
withdraw()
elif(userchoice == 2):
deposit()
elif(userchoice == 3):
inquiry()
elif(userchoice == 4):
exit()
else:
print("pin doesnot match")
attempts = attempts - 1
ATM()

else:
print("*"*10)
print("your account is blocked")
exit()


def withdraw():
global total_balance
amount = int(input("enter the amount in multiple of 1000 : "))
if amount>total_balance:
print("insufficient balance")
ATM()
else:
total_balance = total_balance-amount
print("please collect your card and cash .....")
print(f"your account is debited with Rs {amount} ")
print(f"And remaining balance is : {total_balance}")
print("Thank you for using NIC ASIA Bank")


def deposit():
global total_balance
amount = int(input("enter the amount you want to deposit : "))
if(amount >0):
total_balance += amount
print(f"your account is creadited with Rs {amount} and the new balance is : {total_balance}")
ATM()


else:
print(" \nAmount must be greater than 0 \n ")
deposit()


def inquiry():
print(f"your total balance is {total_balance}")

ATM()
110 changes: 110 additions & 0 deletions 54ntu/filehandlings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import os
def fileHandlingFunc():
choice = int(input("select which operation you want to perform: \n 1. create file 2.write text into file \n 3.Append data 4.delete file \n 5.Read "))

match choice:
case 1:
create_file()


case 2:
writeText()

case 3:
Append()

case 4:
delete()

case 5:
Read()



def create_file():
filename = input("enter file name with extension: ")
if(os.path.exists(filename)):
print("\n")
print("*"*10)
print("file already exists!!!!!")
print("*"*10)

print("\n")
fileHandlingFunc() # calling the main function
else:
print(filename)
f= open(filename,"x")
print("*"*10)

print(f"file has been successfully created!!!! your file name is : {f.name}")
print("*"*10)
fileHandlingFunc()


def writeText():
filename = input("enter the filename where you want to write text : ")
try:
f= open(filename,"w")
content = input("enter the content text : ")
f.write(content)
f.close()
print(f"content is added into your file : {content}")
fileHandlingFunc()
except Exception as e:
print(f"error while writing text to file {e}")
fileHandlingFunc()


def Append():
filename = input("enter the filename where you want to append data: ")
try:
f= open(filename, "a")
content = input("enter the text to append into the file : ")
f.write(content)
f.close()
print("content successfully append to the file...")
fileHandlingFunc()
except Exception as e:
print(f"error while appending text into a file {e}")
fileHandlingFunc()



def delete():
filename = input("enter the filename to delete: ")
try:
if not os.path.exists(filename):
raise FileNotFoundError("file does not exist,please enter the valid filename:::::)) ")
os.remove(filename)
print('file deleted successfullt!!!')
fileHandlingFunc()
except Exception as filenotFound:
print(filenotFound)


except Exception as e:
print("error deleting file : ",e)





def Read():
try:
filename = input("enter the filename to read : ")
if not os.path.exists(filename):
raise FileNotFoundError("file not found please enter valid filename to read :)")
f=open(filename,"r")
print(f.read())

except Exception as filenotfound:
print("\n")
print("*"*10)
print(filenotfound)
print("*"*10)
fileHandlingFunc()




fileHandlingFunc()
54 changes: 54 additions & 0 deletions 54ntu/quiz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@


question = [{
"question": "What is the correct way to create a function in Python? \n A.def myFunction(): B.create myFunction(): \n C.function myfunction(): ",
"answer": "A"
},{
"question": "Which of the following is Immutable datatypes? \n A.List B.Dictionary \n C.String D.Sets",
"answer": "C"
},{
"question": "which statement is used to stop a loop? \n A.break B.exit \n C.return D.stop",
"answer": "A"
},{
"question": "Which method can be used to return a string in upper case letters ? \n A.upper() B.upperCase() \n C.toUpperCase D.upperCase",
"answer": "A"
},{
"question": "Which method can be used to remove any whitespace from both the beginning and the end of a string? \n A.trim() B.strip() \n C.len() D.prtim()",
"answer": "B"
},{
"question": "In Python, 'Hello', is the same as 'Hello'? A.True B.False",
"answer": "A"
}]


def Quiz():
correct_answer = 0
wrong_answer = 0
wrong_answer_list = []
correct_answer_list = []

query = input("woud you like to play game : Y/N : ")
if(query.lower() =="y"):


for i in range(len(question)):
print(question[i]["question"])
answer = input("Enter your answer : ")
if(answer.upper() ==question[i]["answer"]):
print("correct answer")
correct_answer =correct_answer+1
correct_answer_list.append(question[i]["question"])
else:
print("wrong answer")
wrong_answer =wrong_answer+1
wrong_answer_list.append(question[i]["question"])

print(f" you have given total {correct_answer} correct answer")
print(f"correct answer list are : {correct_answer_list}")
print(f"you have given total {wrong_answer} wrong answers")
print(f"wrong answer lists are {wrong_answer_list}")

else:
print("thank you !!!!")

Quiz()
48 changes: 48 additions & 0 deletions 54ntu/registeration&&login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
is_loggedIn = False
database = []


def mainFunction():
choice = input("1. Register 2. Login\n")
if choice == "1":
register()
elif choice == "2":
login()
else:
print("Invalid choice")
mainFunction()


def register():
name = input("Enter your name: ")
email = input("Enter your email: ")
password = input("Enter your password: ")

# Check if the email already exists in the database
for userdata in database:
if userdata['email'].lower() == email.lower():
print("Email already exists")
mainFunction()

newdata = {"name":name,"email":email,"password":password}
database.append(newdata)
print("data inserted successfully")
mainFunction()


def login():
email = input("Enter your email: ")
password = input("Enter your password: ")
for userdata in database:
if((userdata['email'].lower() == email.lower()) and (userdata['password'] == password) ):
is_loggedIn = True
print("You are logged in")
print(f"loggedin status is {is_loggedIn}")
print(f"database values are {database}")
else:
print("creadentials are not matching")
print("*"*10)
print("enter your email and password again ")
login()

mainFunction() # main function is called
82 changes: 82 additions & 0 deletions 54ntu/todoapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# def todos(todo):
# todosItem = []
# # print(type(todosItem))
# def addTodos(todo):
# pass


# todos(input("enter your todo item"))


# todolist = []
# def todos(num):
# if num == 1:
# AddTodo()

# elif num == 2:
# RemoveTodo()


# def AddTodo():
# todo = input("enter your todos : ")
# # print(todo)
# todolist.append(todo)
# userAns = input("would you like to add more: yes or no : ")
# if (userAns.lower() == "yes"):
# AddTodo()
# else:
# print(f"your todos list are : ", todolist)


# def RemoveTodo():
# mytodos = ['going to meeting','going to college','bring cake']
# print(mytodos)
# indexOfTodo = int(input("enter the index of the todo item to be removed : "))
# if(indexOfTodo.isnumeric):
# mytodos.pop(indexOfTodo)
# print(f"mytodos after removing todo at index {indexOfTodo} : {mytodos}")

# else:
# print('you have entered non integer values: ')

# todos(int(input("what you want to do Add or remove 1 for add and 2 for remove : ")))


# second method

todolist = []
def todos(num):
if num == 1:
AddTodo()

elif num == 2:
RemoveTodo()

def AddTodo():
todo = input("enter your todos : ")
# print(todo)

todolist.append(todo)

userAns = input("would you like to add more: yes or no : ")
if (userAns.lower() == "yes"):
AddTodo()
else:
print(f"your todos list are : ", todolist)
removeQuery = input("want to remove your todos yes or no : ")
if(removeQuery.lower() == "yes"):
RemoveTodo()
else:
print("thank you ")

def RemoveTodo():
print("*"*10)
print(todolist)
indexOfTodo = int(input("enter the index of the todo item to be removed : "))
todolist.pop(indexOfTodo)
print(f"mytodos after removing todo at index {indexOfTodo} : {todolist}")



# function calling with the user input queries
todos(int(input("what you want to do Add or remove 1 for add and 2 for remove : ")))