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
Rudiy27
4 years ago
6

Create a function generateString(char, val) that returns a string with val number of char characters concatenated together.

Computers and Technology
1 answer:
NikAS [45]4 years ago
3 0

Answer:

Here is the function generateString() which has two parameters char for storing characters of a string and val is a number in order to return string with val number of char characters.        

def generateString(char, val):

 result = char * val

 return result      

If you want to see if the function works correct and generates right output you can check it by calling the generateString() function and passing values to it and printing the result using print() function as following:

print(generateString('a',7))

This will produce the following output:

aaaaaaa

   

Explanation:

The complete program is:

import sys

character= sys.argv[1]

count= int(sys.argv[2])

# Your code goes here

def generateString(char, val):

 result = char * val

 return result

print(character*count)

The logic of this function generateString(char, val) is explained below.

Lets say the value of char = a and val = 3 This means that generateString() should return 3 a's concatenated together. This concatenation is done by multiplication of the value of char i.e. 3 with the value of val i.e. 3.

So printing a 3 times displays aaa  

You might be interested in
How many total numbers can be represented with an 8-bit binary (base-2) system?
ddd [48]

Answer:

256

Explanation:

4 0
3 years ago
How a student can use computer to improve academic performance?
nikdorinn [45]

Answer:

k Nishant

Explanation:

he can learn many things internet by using computer he change his self by learning about many things

3 0
3 years ago
Read 2 more answers
To “synthesize” means to combine information to create new information.<br> YES or NO
KIM [24]

Answer:Yes

Explanation:

6 0
3 years ago
Read 2 more answers
I have been trying to use brainly recently but i cant because everytime i watch an ad to get an answer, its an interactive ad, s
Troyanec [42]

Answer:

remove ads

Explanation:

by buying a no ad pack

5 0
2 years ago
Write a static method called bothStart that allows the user to input two Strings and returns the String that is the longest subs
marishachu [46]

Answer:

  1.    public static String bothStart(String text1, String text2){
  2.        String s = "";
  3.        if(text1.length() > text2.length()) {
  4.            for (int i = 0; i < text2.length(); i++) {
  5.                if (text1.charAt(i) == text2.charAt(i)) {
  6.                    s += text1.charAt(i);
  7.                }else{
  8.                    break;
  9.                }
  10.            }
  11.            return s;
  12.        }else{
  13.            for (int i = 0; i < text1.length(); i++) {
  14.                if (text1.charAt(i) == text2.charAt(i)) {
  15.                    s += text1.charAt(i);
  16.                }else{
  17.                    break;
  18.                }
  19.            }
  20.            return s;
  21.        }
  22.    }

Explanation:

Let's start with creating a static method <em>bothStart()</em> with two String type parameters, <em>text1 </em>&<em> text2</em> (Line 1).  

<em />

Create a String type variable, <em>s,</em> which will hold the value of the longest substring that both inputs start with the same character (Line 2).

There are two possible situation here: either <em>text1 </em>longer than<em> text2 </em>or vice versa. Hence, we need to create if-else statements to handle these two position conditions (Line 4 & Line 13).

If the length of<em> text1</em> is longer than <em>text2</em>, the for-loop should only traverse both of strings up to the length of the <em>text2 </em>(Line 5). Within the for-loop, we can use<em> charAt()</em> method to extract individual character from the<em> text1</em> & <em>text2 </em>and compare with each other (Line 15). If they are matched, the character should be joined with the string s (Line 16). If not, break the loop.

The program logic from (Line 14 - 20) is similar to the code segment above (Line 4 -12) except for-loop traverse up to the length of <em>text1 .</em>

<em />

At the end, return the s as output (Line 21).

5 0
3 years ago
Other questions:
  • The term composite would be used to describe an image that was altered by the Crop tool.
    15·1 answer
  • An unwanted program that can spread itself to other computers is called what?
    15·2 answers
  • The mac group does not replace the primary functions of eocs or other dispatch organizations. True or False
    8·1 answer
  • Which actions did Sheila have to take to make the changes observed? Check all that apply.
    9·1 answer
  • What is the best operating system
    12·1 answer
  • What does a proxy server do?<br> Help please!!
    12·1 answer
  • Describe the process of normalization and why it is needed.
    12·1 answer
  • 334. Universal Containers uses a custom field on the account object to capture the account credit status. The sales team wants t
    12·1 answer
  • The local library dealing with a major computer virus checked its computers and found several unauthorized programs, also known
    12·2 answers
  • Sendddd meeeee memessss plsssssss
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!