Question

Write the code using FileIO in python to: 1. Calculate the amount of days in a...

Write the code using FileIO in python to:

1. Calculate the amount of days in a given month and year, taking into account leap years and past/future status.

2. Count the number of constances, vowels, whitespace, and other characters within a given string.

Homework Answers

Answer #1

Here I am providing answer for the above questions:

1).

monthrange is function which will take 2 inputs ( year and month ), and returns two inputs (first week day of month taking monday as '0' and no.of days in the month).

Example Code:

>from calendar import monthrange

>monthrange(2019, 10) #asking for october month in 2019.

Result:

>(1, 31) #here 1st of oct is tuesday so it is giving '1'(taking monday as '0') and no.of days in october are '31'.

2).

f = open("test.txt",'r') #opening the file
string=f.readline() # reading the string from file
vowels=0 #initializing variables to '0'
consonents=0
whitespaces=0

for element in string: #iterating over string t
if (element == 'a' ||element == 'e' ||element == 'i' ||element == 'o' ||element == 'u' ||element == 'A' ||element == 'E' ||element == 'I' ||element == 'O' ||element == 'U' ):
vowels++
elif(element == ' '):
whitespaces++
else:
consonents++
print(vowels)
print(consonents)
print(whitespaces)

Hoping that the above answer will help you...Thank you...

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Problem: Write a Python module (a text file containing valid Python code). This file will contain...
Problem: Write a Python module (a text file containing valid Python code). This file will contain the following. Definition of a list containing strings which are in turn integers. These integers represent years, which will be used as inputs to the next item in the file Definition of a function named isLeap. This function must accept a string containing an integer that will be interpreted by this function as a year. If the year is prior to the introduction of...
1.Write a function which takes a string that contains two words separated by any amount of...
1.Write a function which takes a string that contains two words separated by any amount of whitespace, and returns a string in which the words are swapped around and the whitespace is preserved. Hint: use regular expressions where \s detects the whitespaces in a string. Example: given "Hello     World", return "World         Hello" 2.Pandas exercises: Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. Write a python program using Pandas to...
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains...
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains at least three digits. (b) Capture any word that starts with one lowercase character, and either ends with two digits or with three vowels. 2. Given the following statements: string = """ Supreme executive power derives from a mandate from the masses , not from some farcical aquatic ceremony .""" words = string . split () Write a short program, using the re module,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
8) Write Python code for a function called occurances that takes two arguments str1 and str2,...
8) Write Python code for a function called occurances that takes two arguments str1 and str2, assumed to be strings, and returns a dictionary where the keys are the characters in str2. For each character key, the value associated with that key must be either the string ‘‘none’’, ‘‘once’’, or ‘‘more than once’’, depending on how many times that character occurs in str1. In other words, the function roughly keeps track of how many times each character in str1 occurs...
hi can i please get the answer of this question? Write a python program that calculates...
hi can i please get the answer of this question? Write a python program that calculates the average of numeric values in a string and ignores all other characters. Your program must print the sum and average on the screen. (Save your script as spotNumbers.py and spotNumbers.txt) For example: If the input is: myString= "Biology = 66.0 Python = 90.0 Economics = 80.0 Statistics = 70.0" The output wound be: Sum= 306.0 Average= 76.5 Hint: Consider using type build-in function...
PYTHON Write some code to read in a sequence of 10 doubles from the keyboard using...
PYTHON Write some code to read in a sequence of 10 doubles from the keyboard using loops, determine the position of the smallest number in that sequence.
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words. Here is how your program should work...
By using Python code answer the following parts: A) Write a program to ask the user...
By using Python code answer the following parts: A) Write a program to ask the user to input their name and then output the type and length of the input. B) Write a program to output the last 11 letters of 'Introduction to Indiana'. C) Write a program to output the 3rd to the 11th letters of 'Introduction to Indiana'. D) Write a program to ask the user to input a float number and output the rounded value of it...