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...
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...
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...
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....
Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description: You’ve been stuck in NYC for around 8 months all by yourself because you haven’t been able to find a good time to fly home. You’re willing to go to any city but want to see how many flights to each location fit your budget. You’re given a dictionary that has city names (strings) as the keys and a list of prices (list) and...
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...
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...
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...
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...
5. What does this error refer to?Traceback (most recent call last): File "program.py", line 2, in times[2] = 10TypeError: 'tuple' object does not support item assignment * 6. Like most other builtin Python data types, tuples can be compared using the standard comparison operators. True or False? * True False 7. The easiest way to think about sets is that they are like dictionaries without values; that is, the keys in a dictionary are a set. True or False? *...