Work out a circle's area and the distance round it, rounded to 2 places.
Maths & round()Beginner
Built from 3 kinds of block, between Start and End. Each one has a guide.
B4Coder writes the same program as real code. Change the flowchart in the editor and the code changes with it.
import math
def round_half_up(x, digits=0): # Like round() in B4Coder: a half goes up, so 2.5 is 3 (Python's round() gives 2). scale = 10 ** digits whole = math.floor(x * scale) if x * scale - whole >= 0.5: whole += 1 return whole if digits == 0 else whole / scale
radius = float(input("What is the circle's radius (in cm)? "))area = round_half_up(3.14159 * radius * radius, 2)around = round_half_up(2 * 3.14159 * radius, 2)print("Area: " + str(area) + " square cm")print("All the way round: " + str(around) + " cm")How each block becomes code: Python · Java · C++ · C# · JavaScript