The variable "s"
contains a string value. Which of the following will print each
character in this string exactly one time?
# Option A
for ch in s: print(ch)
# Option B
countB = 0 while countB < len(s): print(s[countB]) countB += 1
# Option C
countC = len(s) - 1 while countC >= 0: print(s[countC]) countC -= 1
Option A |
Option B |
Option C |
All of the above |
None of the above |
The variable "s" contains a string value. Which of the following will print each character in...
1) Which of the following is NOT true about a Python
variable?
a) A Python variable must have a value
b) A Python variable can be deleted
c) The lifetime of a Python variable is the whole duration of a
program execution.
d) A Python variable can have the value
None.
2) Given the code segment:
What is the result of executing the code segment?
a) Syntax error
b) Runtime error
c) No error
d) Logic error
3) What...
Question 1 Select all the choices producing a string which contains multiple lines? Examples of each of the choices are presented below. #---------Option A--------------- s = ("Line 1","Line 2") #---------Option B--------------- s = """Line 1 Line 2""" #---------Option C--------------- s = "Line 1\nLine 2" #---------Option D--------------- s = "Line 1" + "Line 2" #Option D Make your statements look the same as the examples. A. Using commas to separate lines B. Using triple-quotation marks C. Adding the newline character between...
Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){ char str[1000], ch; int i, frequency = 0; clock_t t; struct timespec ts, ts2; printf("Enter a string: "); gets(str); int len = strlen(str); printf("Enter a character...
Define a function called repeat_middle which receives as parameter one string (with at least one character), and it should return a new string which will have the middle character/s in the string repeated as many times as the length of the input (original) string. Notice that if the original string has an odd number of characters there is only one middle character. If, on the other hand, if the original string has an even number of characters then there will...
Python
The Python "<" and ">" comparison operators can be used to compare which string variable has a greater value based on comparing the ASCII codes of the characters in each string, one by one. To take some examples: "tets" > "test" returns True because the third letter of the first string, "t", has a greater value than the third letter of the second string, "s". "testa" > "test" returns True because—while the first four letters in both words are...
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0...
2.)Which character is used to denote a comment? A.) # B.) \ C.) % D.) ' 3.)Which of these tasks is impacted by both Option Strict and Option Explicit? A.) Declaring a variable B.) Masking C.) Interpreting an event D.) Casting a variable at some point after it has been declared 4.) What happens when you type a line such as this: variable *=5 A.) Multiply the current value of the variable by 5 and store it as variable B.)...
Python Language Problems 1. isdigit() A. Returns True if this string is just a digit. B. Returns True if this string contains only number characters. C. Return True if this string has at least one number character. D. is not a valid function. 2. Pick the most accurate interpretation for the if construct: if letter in words: print("Got it") A. If the character letter existed in the string words, it prints "Got it". B. It traverse through the string words,...
I have a problem with my C code. Its suppose to print a random
string of length 10 and sometimes it does, but sometimes it prints
a shorter string.
int main() { int len = 10; char key[len+1]; srand(time(0)); int i; for (i=0; i<len; i++) { key[i] = rand()%256; if (key[i] == EOF || key[i] == '\0'). key[i] = 1; key[i] = '\0'; printf("The generated key is %s\n", key);
22. t 0 means 28. input sign value 10 to variable t B) check if variable t is equal to 10 C) none of the above D) both A and B function will always returm an A) integer B) floa string D) boolean 23. See the code below 29. Given valueh if age18 True and values-Ti print ("Pass") valueA and valueb-2 print ("Fail) A) True False for the value of age 20, what is the outpu? A) Pass BT Fail...