M

@mitalipuri

guess the number

Python
1 year ago
import random lower_bound = 1 upper_bound = 5 max_attempts = 12 secret_number = random.randint(lower_bound, upper_bound)

File handling access mode ACP

Python
1 year ago
# open the file in read mode file_read = open('Sample_File.txt','r') print("File in Read Mode -") print(file_read.read()) file_read.close() # open the file in write mode file_write = open('Sample_File.txt', 'w') # write in the file file_write.write(" File in write mode ....")

Lines in file

Python
1 year ago
# Program to count number of lines in this file # Opening a file file = open("Codingal.txt","r") Counter = 0 # Reading from file Content = file.read() # splitting content into lines # and storing them in a list CoList = Content.split("\n")

codingal.txt

Python
1 year ago
Codingal is on a mission to inspire school kids to fall in love with coding. Coding helps develop logical thinking and problem-solving skills. Coding jobs are the future. They already constitute more than 60% of all the jobs in Science, Technology, Engineering, and Math. While still in school, those who start young will be ahead of everyone by the time they get into college. They will be creators of the future. Do you want to join us too?

file handling2

Python
1 year ago
# open the file in read mode file_read = open('Codingal.txt','r') print("File in Read Mode -") print(file_read.read()) file_read.close() # open the file in write mode file_write = open('Codingal.txt', 'w') # write in the file file_write.write(" File in write mode ....")

file handling1

Python
1 year ago
# open file and store file object in a variable file = open('Codingal.txt') # read the contents of file print(file.read()) # close the file file.close()

value.py

Python
1 year ago
# Define the dictionary d = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50} # Prompt the user to enter a key key = int(input("Enter a key: ")) # Check if the key exists in the dictionary and return the corresponding value if key in d: print("The value for key {key} is:", d[key]) else:

disarium number

Python
1 year ago
# Function to check if the number is a Disarium number def is_disarium(number): # Convert the number to string to easily access individual digits num_str = str(number) sum_of_powers = 0 # Loop through each digit, raising it to the power of its position (index+1) for i in range(len(num_str)): sum_of_powers += int(num_str[i]) ** (i + 1)

Find the value_Acp

Python
1 year ago
# Define the dictionary d = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50} # Prompt the user to enter a key key = int(input("Enter a key: ")) # Check if the key exists in the dictionary and return the corresponding value if key in d: print("The value for key is", d[key]) else:

Slam book

Python
1 year ago
import sys def initial_slambook(): row = int(input("Enter the number of people that will be answering the questions: ")) cols = 6 slam_book = [] print(slam_book) for i in range (row): print("\nEnter contact %d details in the following order (ONLY): "% (i+1)) print("NOTE: * indicates madatory fields")

phonebook

Python
1 year ago
# importing the module import sys # this function will be the first to run as soon as the main function executes def initial_phonebook(): rows, cols = int(input("Please enter initial number of contacts: ")), 5 # We are collecting the initial number of contacts the user wants to have in the # phonebook already. User may also enter 0 if he doesn't wish to enter any. phone_book = []

Fibonacci series

Python
1 year ago
def fib_series(nterms): # first two terms n1, n2 = 0, 1 count = 0 while count < nterms: print(n1) nth = n1 + n2 # update values n1 = n2 n2 = nth

Notes of denominations 500, 200, 100, 50

Python
1 year ago
def no_notes(a): Q = [2000, 500, 200, 100, 50, 20, 10] x = 0 for i in range(7): q = Q[i] x = a//q print("Notes of {} = {}".format(q, x)) a = a%q amount = int(input("Enter Total Amount"))

Star pattern

Python
1 year ago
# Basic Star Pattern print("Star Pattern \n") for i in range(1,6): for j in range(i): print("*", end="") print('\n') #Inverted Star Pattern print("Inverted Star Pattern \n") for i in range(6,1,-1):

Generating random profiles

Python
1 year ago
import random fname = ['John', 'Jane', 'Corey', 'Travis', 'Dave', 'Kurt', 'Neil', 'Sam', 'Steve', 'Tom', 'James', 'Robert', 'Michael', 'Charles', 'Joe', 'Mary', 'Maggie', 'Nicole', 'Patricia', 'Linda', 'Barbara', 'Elizabeth', 'Laura', 'Jennifer', 'Maria','Adam','Sturt','Nikolson','Tom','Harry','Ruskin','Thor','Rocky','Ravid','David','Harris','Eion','Elon','Mark','Will','Chris'] lname = ['Smith', 'Doe', 'Jenkins', 'Robinson', 'Davis', 'Stuart', 'Jefferson', 'Jacobs', 'Wright', 'Patterson', 'Wilk

tuple

Python
1 year ago
# Empty tuple my_tuple = () print(my_tuple) # Tuple having integers my_tuple = (1, 2, 3) print(my_tuple) # tuple with mixed datatypes my_tuple = (1, "Hello", 3.4)

dictionary

Python
1 year ago
# empty dictionary my_dict = {} # dictionary with integer keys my_dict = {1: 'apple', 2: 'ball'} # dictionary with mixed keys my_dict = {'name': 'John', 1: [2, 4, 3]} my_dict = {'name': 'Jack', 'age': 26}

Dog

Python
1 year ago
class Dog: species = "Dog" def __init__(self, name, age): self.name= name self.age= age Nelson = Dog("Nelson", 8) Bruno = Dog("Bruno", 10) print("Nelson Is A {} " .format(Nelson.species))

area and perimeter of circle

Python
1 year ago
class Area: radius= 0 def AreaOfCircle(self,radius): AreaCircle=3.14*radius*radius return AreaCircle def PerimeterOfCircle(self,radius): PerimeterCircle=2*3.14*radius return PerimeterCircle

face

Python
1 year ago
from turtle import * # A function is defined for each part, with following steps # 1. pen up # 2. move to correct position # 3. pen down # 4. draw # 5. return home class Face: