Simon the firefighter has to rescue a family from a burning building. The family is…
- User
Simon the firefighter has to rescue a family from a burning building. The family is located on an upper floor, but unfortunately the fire has already spread and the stairs are not accessible anymore. Build a ladder for Simon so he can reach the family and rescue them.
For every floor you have to print 1 ladder segment. 1 segment looks like this:
Two segments look like this:
Input An integer floor, on which the family is located. Output The ASCII ladder. For example output for number 2 is # #
- Assistant
def build_ladder(floor): ladder = "" for _ in range(floor): ladder += '# #\n' ladder += '####\n' ladder += '# #\n' return ladder
floor = int(input()) ladder = build_ladder(floor) print(ladder)
- User
Simon the firefighter has to rescue a family from a burning building. The family is located on an upper floor, but unfortunately the fire has already spread and the stairs are not accessible anymore. Build a ladder for Simon so he can reach the family and rescue them.
For every floor you have to print 1 ladder segment. 1 segment looks like this:
Two segments look like this:
Input An integer floor, on which the family is located. Output The ASCII ladder. Please write C# code to solve .
- Assistant
Sure! Here's the C# code to solve the problem:
C#using System; class Program { static void Main(string[] args) { int floor = Convert.ToInt32(Console.ReadLine()); string ladder = BuildLadder(floor); Console.WriteLine(ladder); } static string BuildLadder(int floor) { string ladder = ""; for (int i = 0; i < floor; i++) { ladder += "# #\n"; ladder += "####\n"; ladder += "# #\n"; } return ladder; } }Hope this helps! Let me know if you have any other questions.