Question

aNumber = 8 # set a number variable aString = str(aNumber) # this way will work...

aNumber = 8 # set a number variable

aString = str(aNumber) # this way will work
#aString = aNumber # this way will fail

result = 'a string combined with the number: ' + aString
print(result)


# or use it directly in another statement
aNumber = 8
print('a string combined with the number: ' + str(aNumber))

Homework Answers

Answer #1

If you have any doubts, please give me comment...

str function will convert integer/float/list into string format.

we can't directly add integer to string, so that we need convert integer to string by using str function i.e., str(aNumber).

Explanation:

aNumber = 8 # set a number variable

aString = str(aNumber) # this way will work
#aString = aNumber # this way will fail

# the above statement will work but aString variable convert into integer. so for the next statement it raises raises an error

result = 'a string combined with the number: ' + aString
print(result)

Let me know if you have any clarifications. Thank you...

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
     I'm trying to use a nested for-each loop to print out the names in the...
     I'm trying to use a nested for-each loop to print out the names in the two dimensional array but it's printing out "[Ljava.lang.String;@15db9742" instead and I don't understand why. is there another way to print out the both array using a nested for each loop?     public static void main(String[] args) {         String[][] str = {{"Steve", "Rick", "John"},{"Erick","Bob","Dave"}};                for(String[] s : str){             for(String e : s){             System.out.println(s);                       }         }       }...
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users...
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users guess value to zero so we enter the loop guess = 0 while guess == computer_num guess = input ("Enter a guess (1-10)") print("Correct the number is "+str(computer_num)) How many times will “Correct the number is…” print when this code block is executed?.
5) Write a java program with scanner object to input first number and second number as...
5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement. Steps: 1) Declare scanner object 2) Ask system out print for first number and declare variable first number 3) Ask system out print for second number and declare variable second number 4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and...
Question 13 options: Two Way ANOVA. A forester is trapping spruce moths. The traps are set...
Question 13 options: Two Way ANOVA. A forester is trapping spruce moths. The traps are set at four different heights: on the ground, and then at heights that are low, medium, and high. In addition, traps are set with three different baits:   sap, sugar water, and a chemical scent. The number of moths caught in traps is recorded. A two way ANOVA is performed. ANOVA Source of Variation SS df MS F P-value Sample 1981.383 3 660.461 10.450 2.09E-05 Columns...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly dividing by b. Each time a division is performed the remainder and quotient are saved. At each step, the dividend is the quotient from the preceding step; the divisor is always b. The algorithm stops when the quotient is 0. The number in the new base is the sequence of remainders in reverse order (the last one computed goes first; the first one goes...
Write a program that reads in a line consisting of a student’s name, Social Security number,...
Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [] to access a string element....
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set it equal to the empty string (NAME=””). Create a variable called NAME_LENGTH and set it equal to the length of your last name. Output the value of the NAME variable to show that it is empty. 2. Write a FOR loop that executes as many times as there are letters in your name (use the NAME_LENGTH variable in your condition). Use a CASE statement...
Use the Pythone programming language. see the #bold hashtags in the code for instructions. Also use...
Use the Pythone programming language. see the #bold hashtags in the code for instructions. Also use the website provided for an idea on how the code should be approached. please provide the code along with a screen shot of the code working with the outcome. s1 = str("abc text xyz") print("String s1 =", s1) print("First letter of s1 = ", s1[0]) print("length of s1= ", len(s1))#len for length length = len(s1) last = s1[length-1] print("Last letter = ", last) print("First...
Which of the following is an example of the correct way to specify a variable number...
Which of the following is an example of the correct way to specify a variable number of arguments to a function in Python? variable_args *args [args] arg1, arg2, arg3, ...
The number of coins that Josh spots when walking to work is a Poisson random variable...
The number of coins that Josh spots when walking to work is a Poisson random variable with mean 6. Each coin is equally likely to be a penny (1), a nickel (5), a dime (10), or a quarter (25). Josh ignores the pennies but picks up the other coins.  Find the probability that Josh picks up exactly 25 cents on his way to work.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT