Pre-work Shop T1

PHOTO EMBED

Thu Jan 19 2023 07:34:50 GMT+0000 (Coordinated Universal Time)

Saved by @Shaghaf_2000 #python

def generate_magic_sequence(start,increment,limit):
    # 1. validation:
    # Start:
    try:
        start = int(str(start))
        if not(start>=1):
            print("start ia not in range")
            return None
        print("Good start value.")
            
    except ValueError:
        # To understand what's going on
        print("conversion faild")
        return None
    
    
        
    # increment:
    try:
        increment = int(str(increment))
        if not(1<= increment <= 10):
            # To understand what's going on
            print("increment is not in range")
            return None
        print("Good increment value")
            
    except ValueError:
        # To understand what's going on
        print("conversion faild")
        return None
    
         
    # limit:
    try:
        limit = int(str(limit))
        if limit<=3 or limit >=99:
            print("limit is not in range")
            return None
        print("Good limit value")
        
    except ValueError:
        print("Conversion faild")
        return None
    
         
    # 2. Generate a sequence:
    sequence = []
    # create the first value here!
    sequence.append(start**5)

    # create a loop within a certaian condition:
    while len(sequence) < limit:
        # define a variable that contains the new values
        # last digit: (sequence[-1])[-1]
        nextValue = (int(str(sequence[-1])[-1])+increment)**5
        #nextValue= (int(str(sequence[-1])[-1] + increment))**5
        sequence.append(nextValue)
    return sequence

result = generate_magic_sequence(3,2,4)

print(result)
content_copyCOPY