How to take inputs and validate them
We are starting by defining a function call welcomeNote
def welcomNote():
name = input('What is your name ? : ')
print("Hello, {}, 'welcome to G-Jeotech Innovation Technology".format(name))
print("Kindly fill in the details \n")
return name
Here we are to get the name input be defining a new fun called profile
def profile():
year = int(input('What is the current year? (eg. 2020) ?: '))
age = int(input('What year were you born: ?'))
location = input("Your current address? : ")
d_o_b = year-age
return age, location, d_o_b
Then here we are to out the previous two functions by defining a new function called outputDate with multiple arguments
def outputData(name, age, location, d_o_b):
print(f"Hello!, {name}")
print("You were born in the year {}, therefore, you are {} years old".format(age,d_o_b))
print(f"And your current home address : {location}\n")
Lastly , we called the functions to displayed the inputs
name = welcomNote()
age,location,d_o_b = profile()
print("\nBelow is the brief summmary of your personal data in our database:\n")
outputData(name,age,location,d_o_b)
## Find and replace function
_This simple Python program allows a user to replace a specific word in a sentence with another word of their choice. Here's how it works:
- User Input for Sentence:
The program prompts the user to input a sentence using input('Enter Your sentence:'). It then prints the original sentence entered.
2.Word Replacement:
The user is asked to specify the word they want to replace (word1) and the word they want to replace it with (word2).
- Word Replacement Action:
Using the replace() method, the program replaces all occurrences of word1 in the original sentence with word2 and displays the modified sentence.
Example:
Input sentence: "The sky is blue."
Replace word: "blue" with "green."
Output: "The sky is green."
_
sentence = input('Enter You sentence :')
print("Your sentence is: ", sentence)
word1 = input("You are replacing :")
word2 = input("With :")
print()
print(sentence.replace(word1, word2))
## Users Inputs registration and Validation method
_This Python program simulates the process of creating an account and logging in with username and password validation. Here's how it works step by step:
- Create Account:
The program first asks the user to enter a username and a password using input(). These values are saved as variables (username and password).
After the user inputs the details, it prints a confirmation message: "Your account has been created successfully".
- Login Process:
The program then prompts the user to log in by asking for the username and password again.
This process is inside a while loop, which means it will continue until the correct login credentials are provided.
- Credential Validation:
In each iteration of the loop, the user is asked to input the username (namevali) and password (pwordvali).
If the entered username and password match the ones initially created by the user, the program prints "Logged in successfully" and exits the loop using the break statement.
- Handling Incorrect Credentials:
If the username and password do not match, the program prints "Invalid credentials, please try again." and continues to prompt the user for their login details.
The loop keeps running until the correct credentials are entered.
_
print("CREATE ACCOUNT")
print()
username = input("Enter username: ")
password = input("Enter password: ")
print("Your account has been created successfully")
print("Login now!")
# Start a loop to validate credentials until they match
while True:
namevali = input("Enter username: ")
pwordvali = input("Enter password: ")
if username == namevali and password == pwordvali:
print("Logged in successfully")
break # Exit the loop if credentials match
else:
print("Invalid credentials, please try again.")
## Calculator Method 1
#Calculator code
#return x - y:
#this function add two numbers
def addition(x, y):
return x + y
#this function subtract two numbers
def substract(x, y):
return x - y
# This function multiplies two numbers
def multiply(x, y):
return x * y
# This function divides two numbers
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
# Take input from the user
choice = input("Enter choice(1/2/3/4): ")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if choice == '1':
print(num1,"+",num2,"=", addition(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", substract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input/Choice")
## Method 2:
fn = int(input("Enter first number : "))
sn = int(input("Enter second number :"))
opt = input("Your Entered Operator : ")
if opt == '+':
print("The addition of ", fn, "and", sn, "is :",fn+sn)
if opt == '-':
print("The subtraction of", fn, "minius", sn, "is :" ,fn-sn)
if opt == '*':
print("The multiplication of" , fn, "times", sn, "is :",fn*sn)
if opt == '/':
print("The division of", fn, "divided by", sn, "is :",fn/sn)
elif opt != opt:
print('Enter the right operator')
else:
print("")
Lastly, what i want us to talk about is Notification Displayer
This script is used to send desktop notifications to the user. The notification can be customized with a title, message, and additional details (like the app name). You might use this for alerting users to important events, reminders, or updates from your application.
import time
from plyer import notification
# Delay for 5 seconds
#time.sleep(5)
# Display a notification
notification.notify(
title='Hello',
message='This Is a Notification from Joshua',
app_name='G-Jeotech',
timeout=30
)
Feel free to watch my previous videos on software development, AI, ML, Data Science and, IT related topics.
You can encourage me by simply hitting the subscribe button to follow my YouTube page, like, and don't forget to drop your comment in the comment section.
https://www.youtube.com/@Ifechuku.G.JeoTech
Top comments (0)