Reputation: 21
Width, Height and Depth of small box: 1x1x1
Width, Height and Depth of big box: 3x3x3
Number of 1x1x1
that will fit in 3x3x3
box is: 27
I have an exercise like that using python3 to get the outcome.
I did:
sb = input("Width, Height and Depth of small box: ")
s= 'x'
And then use print(s.join(sb))
, but i then create new line with 1x1x1 after type 111 and enter which i do not want. I just want it to be exact on the same line of W, H and D of small box (of course with the join).
But the grading system from my student learning not only decline the answer with newline for 1x1x1, they also stated that the error as "1xxx1xxx1". But it is exactly 1x1x1 on the newline.
Upvotes: 1
Views: 98
Reputation: 154
You may try:
eval('1x1x1'.replace('x', '*'))
#1
eval('3x3x3'.replace('x', '*'))
#27
and then divide these 2 results as:
eval('3x3x3'.replace('x', '*')) / eval('1x1x1'.replace('x', '*'))
However, it is not a good practice.
Upvotes: 0
Reputation: 164843
Here is an example of how you can format multiple inputs from one string:
sb = input("Width, Height and Depth of small box separated by |: ")
# User enters 3|3|3
s = 'x'.join(sb.split('|'))
print(s)
# 3x3x3
We use |
as an arbitrary delimiter since it is unlikely it will be used for any other purpose.
Upvotes: 1