0% found this document useful (0 votes)
31 views2 pages

Major Assignment Outputs

Uploaded by

ayushjena007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Major Assignment Outputs

Uploaded by

ayushjena007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programming In Python (CSE 3142)

Major Assignment Outputs

1. Write a program that converts a binary (base 2) number to a decimal (base


10). Your program should begin by reading the binary number from the user
as a string. Then, it should compute the equivalent decimal number by
processing each digit in the binary number. Finally, your program should
display the equivalent decimal number with an appropriate message.

2. Write two functions, hex2int and int2hex, that convert between hexadecimal
digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F) and decimal (base 10)
integers. The hex2int function is responsible for converting a string containing
a single hexadecimal digit to a base 10 integer, while the int2hex function is
responsible for converting an integer between 0 and 15 to a single
hexadecimal digit. Each function will take the value to convert as its only
parameter and return the converted value as its only result. Ensure that the
hex2int function works correctly for both uppercase and lowercase letters.
Your functions should display a meaningful error message and end the
program if the parameter’s value is outside of the expected range.

3. (Arbitrary Base Conversions) Write a program that allows the user to convert a
number from one base to another. Your program should support bases between 2
and 16 for both the input number and the result number. If the user chooses a
base outside of this range then an appropriate error message should be displayed
and the program should exit. Divide your program into several functions,
including a function that converts from an arbitrary base to base 10, a function
that converts from base 10 to an arbitrary base, and a main program that reads
the bases and input number from the user.

4. Write a function that generates a random password. The password should have
a random length of between 7 and 10 characters. Each character should be
randomly selected from positions 33 to 126 in the ASCII table. Your function will
not take any parameters. It will return the randomly generated password as its
only result. Display the randomly generated password in your file’s main
program.

You might also like