Answer:
An appropriate precondition is:
0 <= n && n <= str.length() - 1
Explanation:
Required:
Write down an appropriate pre-condition for the program
From the question, we understand that the method accepts two parameters:
str -> A string value
n -> An integer value which represents the index of character to return from the string str
It should be noted that:
n must be within the range of 0 and str.length()-1
Take for instance:
str = "ABCDE";
n must be within the range 0 to 4 (inclusive) in order not to raise an exception. This is so because the string index starts at 0 and stops at 1 less than the length of the string.
Hence, the precondition can be written as:
0 <= n && n <= str.length() - 1
Which means: n = 0 to length - 1
Write a program that reads an integer between o and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all the digits is 14. Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10=2 and 932/10 =93. Here is a sample run:
Enter a number between 0 and 1000 : 999
The sum of digits is 27.
Answer:
Answered below
Explanation:
#Program is written in Python programming language
digit = 0
sum = 0
num = int(input("Enter a number between 0 and 1000: ")
#Check that number is within the valid range
if num > 0 and num <= 1000:
while num != 0:
#Isolate each digit
digit = num % 10
sum = sum + digit
#Remove isolated digit from number
num = num/10
else:
print("Number is not within valid range")
#print total sum of digits
print(sum)
Identify the correct characteristics of Python lists. Check all that apply. Python lists are enclosed in curly braces { }. Python lists contain items separated by commas. Python lists are versatile Python data types. Python lists may use single quotes, double quotes, or no quotes.
Answer:
Python lists contain items separated by commas.
Python lists are versatile Python data types.
Python lists may uses single quotes, double quotes, or no quotes.
Explanation:
Python Lists are enclosed in regular brackets [ ], not curly brackets { }, so this is not a correct characteristic.
Answer:
a c d
Explanation:
What email program would you suggest and why?
Answer:
An email program
Explanation:
And why?
Answer:
I would suggest g m a i l.
Explanation:
I use G m a i l all the time and I think it is easy to use! A lot of people think it is great too! :)
Gamification and virtual reality is the future of education
Answer:
Education is expected to be the fourth largest sector for VR investment. VR in education is predicted to be a $200 million industry by 2020, and a $700 million industry by 2025. 97% of students would like to study a VR course.
Explanation: