1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
djyliett [7]
3 years ago
9

The create_python_script function creates a new python script in the current working directory, adds the line of comments to it

declared by the 'comments' variable, and returns the size of the new file. Fill in the gaps to create a script called "program.py".
def create_python_script(filename):
comments = "# Start of a new Python program"
with ___:
filesize = ___
return(filesize)
print(create_python_script("program.py"))

Computers and Technology
1 answer:
iogann1982 [59]3 years ago
3 0

Answer:

Following are the code to this question:

with open(filename,"w+") as file: #use an open method that open file in w+ mode        

   file.write(comments)#use write method that inputs the value in the file            

   file.close()#closing the file  

import os#import package os for file  

filesize = os.path.getsize(filename)#defining a variable filesize that uses the getsize method to calculate its size.

Explanation:

Following are the full program to this question:

def create_python_script(filename):#defining method create_python_script that accept filename variable as the parameter

   comments = "# Start of a new Python program"#defining a string varaible comments that holds string value      

   with open(filename,"w+") as file: #use an open method that open file in w+ mode        

       file.write(comments)#use write method that inputs the value in the file        

       file.close()#closing the file    

   import os#import package os for file  

  filesize = os.path.getsize(filename)#defining a variable filesize that uses the getsize method to calculate its size.  

 return filesize#return filesize value

print(create_python_script("program.py"))#use print method that call create_python_script and print its return value

Output:

please find program file and its output.

Program description:

In the above-given program, a method "create_python_script" is declared that accept the "filename" as the parameter, inside the method a comments string variable is declared, that holds string value and define an open method to open "program.py" file and assign the string value in the file.

In the next line, the "getsize" method is defined, which counts string value in digits and returns its value and use the print method to call the "create_python_script" with parameter a print its value.

You might be interested in
You typed the word "weather" when you meant to type the word "whether. " When will Writer or Word flag this as a misspelling or
Alenkasestr [34]

The word flag shows misspelling while typing word "weather" instead of "whether"  is depends on the rest of the sentence and how you have your settings for grammar and spell checker.

<h3>What is word flag or spell checker?</h3>

Word flag or spell checker is the tool or software which helps to identify the misspelling or a grammar problem while typing.

The word "weather"  is typed when there was  to type the word "whether. "

Now, before checking that, when will Writer or Word flag this as a misspelling or a grammar problem, first we have to understand the meaning of both the word.

Word "weather"  is the state of atmosphere for different conditions of temperature, pressure, and humanity. While the word "whether " is the expression of confusion between two things.

The option given for this problem are,

  • Depends on the rest of the sentence and how you have your settings for grammar and spell checker
  • Never
  • All the time.

Word flag, tells the incorrect word, spelling or grammatical error in a sentence.

To identify a particular word which is misplaced in place of another almost similar spelled word, it checks the other word and sentence.

If the particular word does not match with the sentence, the  word flag or spell checker shows the error.

Hence, the word flag shows misspelling while typing word "weather" instead of "whether"  is depends on the rest of the sentence and how you have your settings for grammar and spell checker.

Learn more about the spell checker here;

brainly.com/question/515655

6 0
2 years ago
Write a program that uses the function strcmp() to compare two strings input by the user. The program should state whether the f
Andru [333]

user_str1 = str ( input ("Please enter a phrase: "))

user_str2 = str ( input("Please enter a second phrase: "))

def strcmp (word):

user_in1 = int (len(user_str1))

user_in2 = int (len(user_str2))

if user_in1 > user_in2:

return "Your first phrase is longer"

elif user_in1 < user_in2:

return "Your second phrase is longer"

else:

return "Your phrases are of equal length"

3 0
3 years ago
 What should every Software Engineer know about Software Architecture? ”<br> ??
Llana [10]
<span>Answer: -Software architecture isn't about big design up front; -Every software team needs to consider software architecture; -The software architecture role is about coding, coaching and collaboration; -You don't need to use UML; -A good software architecture enables agility.</span>
7 0
3 years ago
Explain the concepts o f polymorphism, Encapsulation, Inheritance in detail with suitable examples?
levacccp [35]

Answer:

Encapsulation:-It is the binding of the data and functions so that they works as one unit.

Inheritance:-When one class acquires the property of another class it is called inheritance.

Polymorphism :-It generally means more than one form

Explanation:

Encapsulation:- class is an example of encapsulation it can hold different data types and functions in a single container called class.

class Name{

public:

string first_name;

string last_name;

void Display()

{

cout<<first_name<<" "<<last_name<<endl;

}

};

Inheritance:-The property of a class acquiring the properties of another class is called inheritance.

Now we will inherit the above defined class.

class person: public Name

{

public:

char gender;

int age;

void Display()

{

cout<<first_name<<" "<<last_name<<gender<<age<<endl;

}

};

int main()

{

Name n;

person p;

n.Display();

p.Display();

}

Polymorphism- There are two types of polymorphism:-

1.Run time polymorphism=The values are decided at run time.

2.Compile time polymorphism=The values are decided at compile time.

Example:-In the above example we have function Display() in both the classes.This is an example of compile-time polymorphism. We are deciding at the time of compilation which display to use.

8 0
3 years ago
What was Pike's objective on his first expedition in 1805?​
Furkat [3]
Zebulon Pike, the U.S. Army officer who in 1805 led an exploring party in search of the source of the Mississippi River, sets off with a new expedition to explore the American Southwest. Pike was instructed to seek out headwaters of the Arkansas and Red rivers and to investigate Spanish settlements in New Mexico.
8 0
3 years ago
Other questions:
  • You friends parents are worried about going over their budget for the month. Which expense would you suggest is NOT a need?
    10·1 answer
  • For electronically deposited funds, such as an employee's direct deposit, when must banks make those funds available to the empl
    8·1 answer
  • The idea generating technique most often used in writing business letter is ?
    9·2 answers
  • One horsepower is equal to how many foot-pounds of work per second?
    10·2 answers
  • On a network, which protocol is responsible for dividing files into chunks, adding headers containing information for reassembli
    10·1 answer
  • Why did Herman Hollerith invent the Tabulating Machine?
    10·1 answer
  • Can you please answer the question in the picture ! :)
    6·1 answer
  • Write a program that allows the user to continuously input the value n until a negative number is entered
    10·1 answer
  • (03 MC)Why is it important to set goals and share them with others?
    11·1 answer
  • The database cannot be migrated to a different engine because sql server features are used in the application’s net code. The co
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!