Questions
Q1:-How to create a comment in Python?
ans:-
1)Single Line Comment-
'#' is used to create a single line comment in
python.
e.g:-
# This is Single Line Comment.
Anything written here is ignored by Python
print("Hello Students!")
2) Multi-Line Comment:-
We can add a multiline comment in python code using
triple quotes
e.g:-
'''
This is a
Multi-Line Comment.
Anything written
here is ignored by Python
'''
print("Hello Students!")
Q2:-way to obtain user input from command line
ans:-
To take input from the user from command line we make
use of a built-in function input().
e.g1
#accept command line input
num=input();
print(num);
Q3:-List standard mathematical operators in python and explain
them
ans:-
i)Addition(+):
adds two operands
Syntax:-a + b
ii)Subtraction(-):
subtracts two operands
Syntax:-a - b
iii)Multiplication(*):
multiplies two operands
Syntax:-a * b
iv)Division -float(/):
divides the first operand by the
second
Syntax:-a / b
v)Division-floor(//):
divides the first operand by the
second
Syntax:-a // b
vi)Modulus(%):
returns the remainder when first
operand is divided by the second
Syntax:-a % b
Q5:- Explain while loop. Give example
ans:-
Repeats a block of statements while a given condition
is TRUE.
Syntax:-
while (Condition):
#block of statements
e.g
#Program to find factorial using
while
print('Enter num to find
factorial:-');
num=input();
i=1
fact=1;
while i < num:
i=i+1;
fact=fact*i
print('Factorial:-');
print(fact);
Questions 1. How to create a comment in python? 2. The way to obtain user input...
python #Ignore line 2, it is just there to align with zybooks requirements print("5") #Create a list with the following numbers and assign it to a variable name: 1,2,3,4,5,6 #Convert the list to a tuple and assign it to a variable name (dirrerent from the list's name) #Try the following and press the run program button to which ones work and which ones cause errors #If a statement causes an error, use a # to comment it out #Add the...
Create a Python list (use first three letters of your name followed by the letter L as the name of the list.) with the following data: 10, 20.0, 50.00, 7000, 7500, 7700, 7800, 8000, 9000, ‘python’. Display the entire list with an appropriate message. Display the 4th element in the list with an appropriate message. Display the first 3 values of the list only. Display all the values starting from the sixth element to the end of the list. Change...
Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called HelperClasses and create a class inside it called Helpers Inside Helpers, create 8 static methods as follows: 1.) Max, Min, Standard_Deviation, Mean a.) Each of these should take a list as a parameter and return the calculated value 2.) Bubble a.) This should take a list as a parameter and return the sorted list 3.) Median a.) This should take a list as a...
In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will count the frequency with which each word appears in the text. 2. Words which are the spelled the same but differ by case will be combined. 3. Punctuation should be removed 4. If the file does not exist, use a ‘try-execption’ block to handle the error 5. Output will list the words alphabetically, with the word...
Hello can anyone help solve this please in Python the way it's
asked?
Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show up at the midterm exam, so it's important to practice. a) Write a list comprehension that returns a list [0, 1,4, 9, 16, .. 625] starting from range(0, 26). (lots of list elements were omitted in ...) b) Write a list comprehension that returns the list...
This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...
Write Python code examples of statements to remove the name at position 2 from the list in problem 32, and to remove one of the remaining names by referencing that name. Write Python code to declare a tuple named stuck that holds the three remaining names from famfri by referencing those names as elemens of famfri. Declare a Python set containing the names of the four seasons. What happens if you declare a set using a list that contains two...
1) We have returned to our ingredients dictionary. We want to display the ingredients in alphabetical order. Dictionaries cannot be sorted, so we need to use the items method to convert the dictionary into a list of tuples. Then we can sort that new list of tuples, then display the ingredients. Use items and list to convert ingredients into a list of tuples. Sort the new list, called ingred_list Write a for loop which goes through each tuple in ingred_list....
1. Pleae write the following code in Python 3. Also, please show all the outputs. . Write a simple Rectangle class. It should do the following: Accepts length and width as parameters when creating a new instance Has a perimeter method that returns the perimeter of the rectangle Has an area method that returns the area of the rectangle Don't worry about coordinates or negative values, etc. Python provides several modules to allow you to easily extend some of the...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...