Python Aiml 4 2
Python Aiml 4 2
"""python_aiml_4_2.ipynb
count_2 = 0
#while True:
#print("infinite loop")
"""'''For Loops'''"""
"""'''Nested Loops'''"""
"""For this quiz, write a short program that simulates a lock system.
In this program, a user should be able to enter the correct username and password
when prompted to do so.
The user gets three tries to enter the correct username and password.
If the user does not enter the correct username and password in those three login
attempts, display to the screen “LOGIN ATTEMPT FAILED: ACCOUNT IS NOW LOCKED.”
If the user is able to enter the correct username and password, display to the
screen “LOGGING INTO ACCOUNT…”
# Welcome Message
print("Welcome to the Lock System!")
print("Please enter your username and password to login to the system.\n")
else:
print("LOGIN ATTEMPT FAILED. ACCOUNT IS NOW LOCKED.")
# This program will ask the user to guess the correct password. If the user.
# does not enter the correct password in 3 attempts, they lose the game.
# Guessing Game
number_of_attempts = 0
password = "gameover"
print("welcome to the guessing game ")
while number_of_attempts < 3:
user_input = input("enter guess..!")
number_of_attempts += 1
if user_input == password :
print("you win ")
break
else:
print("try again")
else:
print("you loose")
import math
"""# import math using a shorter name (this is another option you can use)"""
import math as m
print(m.sqrt(25))
print(math.sqrt(25))
x = sqrt(25)
y = pow(5,2)
print(x)
print(y)
help('math')
"""
import random
print(random.random())
print(random.random())
# Create a program that generates ten random integer values. Display these ten
generated numbers to the screen\n"
import random
random_list_1 = []
for i in range(0,10):
random_number = random.randint(1, 20)
random_list_1.append(random_number)
print(random_list_1)
import random
# The same seed will produce the same sequence of random numbers
random.seed(20)
print(random.randint(1, 10))
print(random.random())
import random
for i in range(2):
# Generated random number will be between 1 to 1000 but different in every run.
print(random.randint(1, 1000))
for i in range(2):
# Any number can be used in place of '0'.
random.seed(2)
# Generated random number will be between 1 to 1000 but same in every run.
print(random.randint(1, 1000))
"""
# Check if the number is equal to the sum of its digits raised to the power of
num_digits
if num == sum:
print(f"{num} is an Armstrong number!")
else:
print(f"{num} is not an Armstrong number.")
"""1)a). Develop a program to read the student details like Name, USN, and Marks in
three subjects. Display the student details, total marks and percentage with
suitable messages."""
"""1)b.) Develop a program to read the name and year of birth of a person. Display
whether the person is a senior citizen or not."""
"""**TEST:**
MODULE1 Questions:
1) Explain with an example: a) input() b) print() c) len() d) format() e) range()
f) sys.exit()
2) Explain in brief string concatenation and string replication with two examples.
3) Explain if, elif, for, while, break and continue statements with examples and
flowcharts.
"""