Pmd091023 (16/10/23)

1.Find out the sum of number without using any in-built function and compulsory using for loop?
numberlist=[23,25,-43,0,-56]

  1. find out the highest number in the following list without using any in-built function and compulsory use a for loop?
    x =[23,25,-43,0,-56]

  2. In the following list of person information:
    persons = [{‘name’:‘Mohit’,‘Gender’:‘M’,‘profession’:‘teacher’},
    {‘name’:‘Kunal’,Gender’:‘M’,'‘profession’:‘engineer’},
    {‘name’:‘Rashmi’,‘Gender’:‘F’,‘profession’:‘doctor’}]

    a. if the profession is doctor check if the name starts with M print ‘doctor M’ else print
    doctor.
    b. if the profession is engineer check if the gender is M , if yes print ‘engineer bhaiya’ , else
    print ‘engineer didi’
    c.if the profession is actor check if the last character of name is h, if yes print actor else
    print liar.
    d. if the profession is none of the above print( ‘Wow , what do you actually do??’)…

Hi @zk6290254938
Did the first two, will do the last one later (absolutely hate the last question)

1 Like

@anjalidalal.work
correct, i understand but that’s how you are going to get the question at the time of interview :grinning:

1 Like

1 Like
  1. Find out the sum of number without using any in-built function and compulsory using for loop?

numberlist = [23, 25, -43, 0, -56]
sum_of_numbers = 0

for number in numberlist:
sum_of_numbers += number

print(sum_of_numbers)

  1. find out the highest number in the following list without using any in-built function and compulsory use a for loop?

x = [23, 25, -43, 0, -56]
highest_number = x[0]

for number in x:
if number > highest_number:
highest_number = number

print(highest_number)

  1. In the following list of person information:

persons = [
{‘name’: ‘Mohit’, ‘Gender’: ‘M’, ‘profession’: ‘teacher’},
{‘name’: ‘Kunal’, ‘Gender’: ‘M’, ‘profession’: ‘engineer’},
{‘name’: ‘Rashmi’, ‘Gender’: ‘F’, ‘profession’: ‘doctor’}
]

for person in persons:
profession = person.get(‘profession’)
name = person.get(‘name’)
gender = person.get(‘Gender’)

if profession == 'doctor':
    if name.startswith('M'):
        print('doctor M')
    else:
        print('doctor')
elif profession == 'engineer':
    if gender == 'M':
        print('engineer bhaiya')
    else:
        print('engineer didi')
elif profession == 'actor':
    if name[-1] == 'h':
        print('actor')
    else:
        print('liar')
else:
    print('Wow, what do you actually do??')
1 Like

1 Like
  1. Question

  2. Question

  3. Question

1 Like