DileepKumarMantena / NewDataEngineeringPractice

0 stars 1 forks source link

Python Practice #1

Open DileepKumarMantena opened 1 month ago

DileepKumarMantena commented 1 month ago

20/9/2024

1.Write a python code to access the api and get the data in a proper format(https://randomuser.me/api/?results=10) 2.write a python code for reading an file and counts the number of lines,words and characters in that file 3.write a python code for reading an file content and writing that content into anthor file 4.Write a python script to add these two dictonaries into one dictoary a={ "name":"deepak", "age:35, } b={ "place":"vizag', "phone":124 }

DileepKumarMantena commented 1 month ago

24/09/2024

Functions: **Write a Python function that takes two numbers as arguments and returns their sum. Use the function to sum two numbers provided by the user.

Create a function that checks if a given string is a palindrome (reads the same backward as forward). Test it with various strings.

Write a Python function that accepts a list of numbers and returns the largest number in the list. Handle the case when the list is empty by returning None.

Create a recursive function that calculates the factorial of a number provided by the user. Ensure to validate the input for non-negative integers.

Write a Python function that accepts a variable number of arguments and returns their average. Test it with different numbers of arguments.

Inheritance: Create a class Animal with a method speak() that prints "Animal speaks". Derive a class Dog that overrides speak() to print "Dog barks". Create objects of both classes and call their speak() methods.

Implement a class hierarchy where Vehicle is the base class and Car and Bike are subclasses. Include attributes such as brand, model, and a method get_info() to display vehicle details. Demonstrate how the subclasses inherit and override the method.

Write a Python program with a base class Person that has attributes name and age. Derive a class Student that inherits from Person and adds an attribute student_id. Create an object of Student and display its attributes.

Dictionaries: Write a Python program that creates a dictionary to store student names as keys and their grades as values. Allow the user to input a student's name and retrieve their grade from the dictionary.

Create a dictionary that stores countries as keys and their capitals as values. Write a function that takes the name of a country as input and returns its capital. If the country is not found, return a message saying so.**

Write a Python program that takes a sentence as input and creates a dictionary that counts the occurrences of each word in the sentence. Print the dictionary with the word frequencies.

Merge two dictionaries: Write a function that takes two dictionaries as input and merges them into one. If there are duplicate keys, the values from the second dictionary should overwrite the first.

Write a Python program that iterates over a dictionary and prints all the keys and values in a nicely formatted way (e.g., Key: value).

DileepKumarMantena commented 1 month ago

11-10-2024 import logging

Basic configuration

logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO,filename='app.log')

age_name=input('enter user age and name:') logging.info(age_name) age=int(age_name[0:2]) logging.info(age) name=age_name[2:]

try: if age>18: logging.info(name) except ZeroDivisionError: logging.error("An error occurred")

DileepKumarMantena commented 1 month ago

password=input("enter your password")

8 words

special character

one number

if the password is matches above conditions then say paswword is valid along with or else say invalid password