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...

  • Question I This question carries 20% of the marks for this assignment. You are asked to...

    Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...

  • 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....

  • 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...

  • 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...

  • Exercise #2: 10 M gals water per day 71-80 81-90 91-100 101-110 111-120 121-130 131-140 10...

    Exercise #2: 10 M gals water per day 71-80 81-90 91-100 101-110 111-120 121-130 131-140 10 M gals water per day 71-80 91-100 101-110 111-120 121-130 131-140 Create a data file named water.dat with the following data: 123 134 122 128 111 110 98 99 78 98 100 120 122 110 111 123 134 122 128 111 110 98 99 78 98 100 120 122 110 111. Each number represents the number of millions of gallons of water provided to...

  • Question 1) Suppose a program has the following code: const int X = 2, Y =...

    Question 1) Suppose a program has the following code: const int X = 2, Y = 3; int sum; int values[X][Y] = {{1, 2, 3},                                  {4, 5, 6}}; for(int i=0; i<X; i++) {      sum=0;      for(int j=0; j<Y; j++)         sum+=values[i][j];    cout<<sum<<endl; } What is this program getting the sum of? Group of answer choices D-) The columns of the 2D array C-) The rows of the 2D array A-) All of the elements of the 2D...

  • Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...

    Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Objective: Write a program that implements the Game of Life cellular automata system invented by John...

    Objective: Write a program that implements the Game of Life cellular automata system invented by John Conway. 1. Create two game grids of size at least 50x50. These grid cells can be either Boolean or integer. In the following, I’ll refer to these as gridOne and gridTwo. 2. Set all cells in both grids to false. 3. Start by initializing gridOne. Allow the user to specify two different ways of initializing the grid: 1) by specifying a pattern file to...

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