Question

Write a psudocode: 1. Define a function called authorize that takes in 2 strings, uName, and...

Write a psudocode:

1. Define a function called authorize that takes in 2 strings, uName, and passwd, as arguments and produces a Boolean as output. Your function should output True if both the username is “batman” and the password is “rulz” and false in any other situation. (KEEP IN MIND: this function didn’t say anything about looping. It performs authentication on only 1 pass)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Pseudo code:

def authorize(uName,passwd) //define the function

{

if(uName=='batman' and passwd=='rulz') return true; //check the condition

else return false;

}

print(authorize('batman','rulz')) //check the output by printing

Python code:

def authorize(uName,passwd):
if(uName=='batman' and passwd=='rulz'):
return True
else:
return False

user_name = input() #username
pass_word = input() #password

print(authorize(user_name,pass_word))

C code:

#include <stdio.h>
#include<string.h>
#include<stdbool.h>

int authorize(char *uName,char *passwd)
{
if(strcmp(uName,"batman")==0 && strcmp(passwd,"rulz")==0) return 1;
else return 0;
}

int main()
{
int a = authorize("batman","rulz1");
if(a==1) printf("True");
else printf("False");
return 0;
}

I have given the pseudo-code and python code, C code for your reference. As you did not mention a particular language, I have given python and C code. The pseudo-code is the same for any programming language. There is no use of a loop for the validation here, only an if-else statement is required. I hope you find this helpful.

Add a comment
Know the answer?
Add Answer to:
Write a psudocode: 1. Define a function called authorize that takes in 2 strings, uName, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT