Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Please explain Python Code
# 2) Write a procedure that takes a string and returns that string ROT13'ed.
def rot13(word):
encryptedword = ""
for c in word:
if c >= 'a' and c <= 'm': # a..m
encryptedword += chr((ord(c)+13))
elif c >= 'n' and c <= 'z': # n..z
encryptedword += chr((ord(c)-13))
else: # don't encrypt letters
encryptedword += c
return encryptedword
#print(rconvertup("example"))
print(rot13("example!"))
print(rot13(rot13("example!")))
def rot13(word):
encryptedword = ""
for c in word:
if c >= 'a' and c <= 'm': # a..m
encryptedword += chr((ord(c)+13))
elif c >= 'n' and c <= 'z': # n..z
encryptedword += chr((ord(c)-13))
else: # don't encrypt letters
encryptedword += c
return encryptedword
#print(rconvertup("example"))
print(rot13("example!"))
print(rot13(rot13("example!")))
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1. Initialize len to 0. 2. Set a variable to the beginning index of string s. 3. Repeat the following step till the string terminator is encountered. 4. len = len +1 5. Exit1. Implement the above algorithms in C/C++arrow_forwardIn C language / Please don't use (sprint) function. Write a function fact_calc that takes a string output argument and an integer input argument n and returns a string showing the calculation of n!. For example, if the value supplied for n were 6, the string returned would be 6! 5 6 3 5 3 4 3 3 3 2 3 1 5 720 Write a program that repeatedly prompts the user for an integer between 0 and 9, calls fact_calc and outputs the resulting string. If the user inputs an invalid value, the program should display an error message and re-prompt for valid input. Input of the sentinel -1 should cause the input loop to exit. Note: Don't print factorial of -1, or any number that is not between 0 and 9. SAMPLE RUN #4: ./Fact Interactive Session Hide Invisibles Highlight: None Show Highlighted Only Enter·an·integer·between·0·and·9·or·-1·to·quit:5↵ 5!·=·5·x·4·x·3·x·2·x·1·x··=·120↵ Enter·an·integer·between·0·and·9·or·-1·to·quit:6↵ 6!·=·6·x·5·x·4·x·3·x·2·x·1·x··=·720↵…arrow_forwardAlert dont submit AI generated answer. Please code in C language.arrow_forward
- 3. Word Counter Write a function that accepts a pointer to a C-string as an argument and returns the number of words contained in the string. For instance, if the string argument is "Four score and seven years ago" the function should return the number 6. Demonstrate the function in a program that asks the user to input a string then passes it to the fune- tion. The number of words in the string should be displayed on the screen. Optional Exercise: Write an overloaded version of this function that accepts a string clás object as its argument.arrow_forwardCode in c++ pleasearrow_forward#include<bits/stdc++.h>using namespace std;bool isPalindrome(string &s){ int start=0; int end=s.length()-1; while(start<=end) { if(s[start]!=s[end]) { return false; } start++; end--; } return true;}int main(){ string s; cout<<"ENTER STRING:"; getline(cin,s); int n=s.length(); bool flag=true; for(int i=1;i<n;i++) { string lowerHalf=s.substr(0,i); string upperHalf=s.substr(i,n-i); if(isPalindrome(lowerHalf) && isPalindrome(upperHalf)) { flag=false; cout<<"String A is:"<<lowerHalf<<"\n"; cout<<"String B is:"<<upperHalf<<"\n"; break; } } if(flag) { cout<<"NO\n"; } return 0;} change to stdio.h string.harrow_forward
- C++ : Write a function that inserts a given string in the middle of a second string. If the second string has an oddnumber of characters, the program first repeats the last character before inserting. Write a program to test your function.arrow_forwardC++ is my answer correct ? Write a function to convert a given string : Answer: #include <iostream> #include <string> using namespace std; void toUpper(string &str) { for (int i = 0; i < str.length(); i++) { str[i] = toupper(str[i]); } } void toLower(string &str) { for (int i = 0; i < str.length(); i++) { str[i] = tolower(str[i]); } } int main() { string str = "khaled"; toUpper(str); cout << str << endl; str = "MOHAMMED"; toLower(str); cout << str << endl; return 0; } Write a function to calculate the sum of the even number from 1 - 100. Answer: #include <iostream> using namespace std; int sumEven() { int sum = 0; for (int i = 1; i <= 100; i++) { if (i % 2 == 0) { sum += i; } } return sum; } int main() { cout << sumEven() << endl; return 0; }arrow_forwardString to integer ATOI (requires use of INT_MAX and INT_MIN): Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). The algorithm for myAtoi(string s) is as follows: Read in and ignore any leading whitespace. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present. Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2). If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education