Answer:
This is using c++ syntax, you might need to make slight adjustment for other languages.
First activity:
string firstSnack = "chips";
string secondSnack = "pizza";
string thirdSnack = "apples";
string bestSnack = firstSnack;
bestSnack = secondSnack;
Second activity:
double apple = 0.5;
double banana = 0.75;
double orange = 1.43;
double total = apple + banana + orange;
Explanation:
When first declaring a variable, you want to specify the type (such as int, double, string, bool, etc.) and then the name. You can set the variable value in the declaration, or you can set it to a value later in the program by not having the equals sign and whatever comes next.
Answer:
see the code snippet below writing in Kotlin Language
Explanation:
fun main(args: Array<String>) {
sumOfNumbers()
}
fun sumOfNumbers(): Int{
var firstNum:Int
var secondNum:Int
println("Enter the value of first +ve Number")
firstNum= Integer.valueOf(readLine())
println("Enter the value of second +ve Number")
secondNum= Integer.valueOf(readLine())
var sum:Int= firstNum+secondNum
println("The sum of $firstNum and $secondNum is $sum")
return sum
}
Answer:
<=
Explanation:
Pretty much the same as in maths
Answer:
def str_analysis(s):
if s.isdigit():
s = int(s)
if s > 99:
message = str(s) + " is a pretty big number"
else:
message = str(s) + " is a smaller number than expected"
elif s.isalpha():
message = s + " is all alphabetical characters!"
else:
message = "There are multiple character types"
return message;
s = input("enter word or integer: ")
while s != "":
print(str_analysis(s))
s = input("enter word or integer: ")
Explanation:
- Check if the string is digit, alphabetical, or mixed inside the function
- Ask the user for the input
- Call and print the result of the <em>str_analysis</em> function inside the while loop
- Keep asking for the input until the given string is empty