Question

rorkyCode.txt x : 5 * 4 - 2; yy : 6! #x; zoo : 120 - X; CA; 10 >A; 20 > A; 30 >A; ; yy > B; 200 > B; Si c; wish : 67 zoo *Symbol Operation Multiply Division Addition Subtraction Assignment - factorial Print to screen Create an empty set @ Creates

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#!/usr/bin/env python
# coding: utf-8

# In[148]:


f=open('C:/Users/RV/rorkycode.txt','r')
code=f.read()


# In[149]:


print(code)


# In[161]:


import copy
lines_of_code=code.split(';')
code_in_py=[]
for line in lines_of_code:
    line=line.replace('\n','')
    count=0
    
    for i in range(len(line)):
        if line[i]=='@':
            l=line[i+2]+'=set()'
            count=1
        
        if line[i]=='!':
            l=line[:i-2].strip()+'math.factorial('+line[i-2]+')'+line[i+1:].strip()
            count=1
        
        if line[i]=='>':
            l=line[i+2:].strip()+'.add('+line[:i].strip()+')'
            count=1
            
        if line[i]=='=':
            l='print('+line[i+2:].strip()+')'
            count=1
        if line[i]=='&':
            l=line[:i-2].strip()+line[i-2]+'.union('+line[i+2]+')'
            count=1
        if line[i]=='|':
            l=line[:i-2].strip()+line[i-2]+'.intersection('+line[i+2]+')'
            count=1
            
        
        
    if(count==1):
        l=l.replace(':','=')
        l=l.replace('~','/')
        l=l.replace('#','+')
        l=l.replace('^','-')
        l=l.replace(' ','')
        code_in_py.append(l.strip())
    else:
        line=line.replace(':','=')
        line=line.replace('~','/')
        line=line.replace('#','+')
        line=line.replace('^','-')
        line=line.replace(' ','')
        code_in_py.append(line.strip())
        

            
        


# In[162]:


print(code_in_py)


# In[167]:


fw=open('C:/Users/RV/rorkycode_py.txt','w+')
fw.write('import math\n')
for line in code_in_py:
    fw.write(line)
    fw.write('\n')


# In[168]:


fr=open('C:/Users/RV/rorkycode_py.txt','r')
d=fr.read()


# In[169]:


get_ipython().system('python C:/Users/RV/rorkycode_py.txt')

code is written in jupyter note book and then converted .py file.

this is the input file:

_______________________________________

x : 5 * 4 ~ 2 ;
= x ;
yy : 6 ! # x ; zoo : 120 * x ;
@ A ; 10 > A ; 20 > A ; 30 > A ;
= A ;
@ B ; yy > B ; zoo > B ;
= B ;
c : A & B ;
= c ;
wish : 67 + zoo * 2 ;
my : 155 ;
my > A ;
wish > c ;
= c ;

________________________________

first I convert it to python syntax file and file looks like

'import math\nx=5*4/2\nprint(x)\nyy=math.factorial(6)+x\nzoo=120*x\nA=set()\nA.add(10)\nA.add(20)\nA.add(30)\nprint(A)\nB=set()\nB.add(yy)\nB.add(zoo)\nprint(B)\nc=A.union(B)\nprint(c)\nwish=67+zoo*2\nmy=155\nA.add(my)\nc.add(wish)\nprint(c)\n\n'

before that I made a list of code that list is look like...

['x=5*4/2',
 'print(x)',
 'yy=math.factorial(6)+x',
 'zoo=120*x',
 'A=set()',
 'A.add(10)',
 'A.add(20)',
 'A.add(30)',
 'print(A)',
 'B=set()',
 'B.add(yy)',
 'B.add(zoo)',
 'print(B)',
 'c=A.union(B)',
 'print(c)',
 'wish=67+zoo*2',
 'my=155',
 'A.add(my)',
 'c.add(wish)',
 'print(c)',
 '']

Now see the output.

10.0
{10, 20, 30}
{1200.0, 730.0}
{1200.0, 20, 730.0, 10, 30}
{1200.0, 2467.0, 20, 730.0, 10, 30}
Add a comment
Know the answer?
Add Answer to:
rorkyCode.txt x : 5 * 4 - 2; yy : 6! #x; zoo : 120 -...
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
  • In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes...

    In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes (name, symbol, numberOfShares, currentPrice and boughtPrice)and one static private attribute (numberOfStocks). All attributes must be initialized (name and symbol to “No name/ symbol yet” and numberOfShares, currentPrice and boughtPrice to 0. Create two constructors, one with no arguments and the other with all the attributes. (However, remember to increase the numberOfStocks in both constructors. Write the necessary mutators and accessors (getters and setters) for...

  • PART 1 PART 2 PART 3 PART 4 PART 5 PART 6 PART 7 PART 8...

    PART 1 PART 2 PART 3 PART 4 PART 5 PART 6 PART 7 PART 8 -11 points BBUnderStat12 22 005 Ask Your Teache My Notes It is costly in both time and money to go to college. Does it pay off? According to the Bureau of the Census, the answer is yes. The average annual income (in thousands of dollars) of a household headed by a person with the stated education level is as follows: 24.9 if ninth grade...

  • please do a and b Lab Exercise 9 Assignment Overview This lab exercise provides practice with...

    please do a and b Lab Exercise 9 Assignment Overview This lab exercise provides practice with dictionaries of lists and sets in Python. A. Write a program using Dictionaries of lists Consider the file named "lab9a.ру" Given two files named exactly continents. txt and cities.txt (no error checking of the file name is needed) of continents, countries and cities. Write a program to read continents, countries and their cities, put them in a nested dictionary and print them (no duplicates...

  • do numbers 4-8 4. Given any directory, use the Is command to display: • all files...

    do numbers 4-8 4. Given any directory, use the Is command to display: • all files and sub-directories starting with the letter "D" (note do not list anything in any sub-directory) • its immediate sub-directories (sub-directories only, and no other ordinary files) its immediate hidden sub-directories only - take a screenshot (#3-3) that clearly shows the command and the result. 5. Assume that the following files are in the working directory: $ ls intro notesb ref2 section 1 section3 section4b...

  • The second phase of your semester project is to write pass one of a two‑pass assembler...

    The second phase of your semester project is to write pass one of a two‑pass assembler for the SIC assembler language program. As with Phase 1, this is to be written in C (not C++) and must run successfully on Linux. Pass one will read each line of the source file, and begin the process of translating it to object code. (Note: it will be to your advantage to have a separate procedure handle reading, and perhaps tokenizing, the source...

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

  • Please assist. I keep getting the error message in the middle screen when I run the...

    Please assist. I keep getting the error message in the middle screen when I run the program on the left. The image on the right is the section of images.py where it's indicating the issue with the .split is. How do I fix this? images.cy - /Users/carrietarpy Downloads/lab9-3/images.py 12.7.18) Python 2.7.18 Shell Python 2.7.15 (v2.7.18:542 102112, Apr 19 2820, 29:48:48) [GCC 4.7.1 Compatible Apple II w 6.3 Clong-FA3.0.57)] on der in Type "help", "copyright', 'credits' or "license()' for more inforyotion...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

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