Malvolio Good

@malvoliothegood (851)
I am not a plastic toy.
A student here learning data handling please do help
posted to Ask by amanh787
  1. You need to create a Python repl
  2. Create the text file 'file1.txt' on your computer, and fill it with some lines of text
  3. Upload the text file by dragging it from your file manager into the files area in your repl
  4. Include the code in your question in main.py
  5. Run your program!

Try getting it working yourself, then compare it to this repl: https://replit.com/@malvoliothegood/readtextfile#main.py

🚀 Creating a VueJS app: A tutorial for beginners 👏
posted to Tutorials by eankeen

Good introduction to Vue.js

2 Errors
posted to Ask by LingWu1

When I run the program I see that there are two errors. The error messages give the line numbers of the code in which the errors occur. When I look at the offending code I could quickly see the errors. They were/are miss-named variables: std -> stud, and File -> fl.

Rot13 cypher
posted to Share by Alto2

@Alto2 Thanks for the explanation. I guess you have heard of the Caesar Cipher as well.

how do i answer this question?
posted to Ask by RossBenson

The division operator ( / ) returns the whole number part of a division. The remainder operator ( // ) returns the remainder part. I won't give you the answer, but here are some clues. Replace the ? marks with the correct operator (or number).

tens = ? / 10
ones = 79 ? 10
Rot13 cypher
posted to Share by Alto2

Interesting. How do you decipher enciphered text? Also, you could make your code slightly more efficient, like so:

for letter in inputStr:

  letter_value = ord(letter)

  if 64 < letter_value < 78 or 96 < letter_value < 110:
    message += chr(letter_value + 13)
  elif 91 > letter_value > 77 or 123 > letter_value > 109:
    message += chr(letter_value-13)
  else:
    message += letter

  return message
How should I implement the algorithm? C++
posted to Ask by DeepGreen

If you do a search on the Net for 'Sieve of Eratosthenes to Generate Primes C++' you will find plenty of example code. Choose the algorithm that you understand the best.

Can't understand error
posted to Ask by Yoplayer1py

@Yoplayer1py When you create a new repl you have to choose a template to base it on. There is a Flask one. I went through the process and created it. You can fork it to get your own version. I think the one you cloned from github is a bit complex. I tried to get it going using a bash template but did not succeed.
Flask Repl: https://replit.com/@malvoliothegood/flask-template

Next.js on replit keeps running out of memory
posted to Ask by Plorzon

It looks like you have a free account rather than a Hacker one. This means you will only be able to access limited resources such as CPU and RAM. Maybe this is why you are running out of memory.

Can't understand error
posted to Ask by Yoplayer1py

I don't know enough about Flask to say what the error is caused by, but is main.py at the right level? Should it be in the root of the project? Have you tried building up your app using the Flask template that repl.it supplies?

numerology calc in c language?
posted to Ask by JohnRuflo

It's not straight forward that's for sure. Do you know about two dimensional arrays, for and while loops? Also string functions like strlen?

I have coded up a solution. It took a while. If you can't create a solution make a comment and I will give you the link to my program. Happy coding.

How to import a file in repl.it
posted to Ask by chidibomaopara

path should be path = r"gun-violence-data-short.csv"

Purple Rain ☂️!
posted to Share by PowerCoder

Here is something like purple rain except it's raining cats and dogs . The HTML5 canvas and its methods are used: https://repl.it/@malvoliothegood/raining-cats-and-dogs

I dont know to use else!
posted to Ask by AlexIsRapling

Your code needs to be indented and you need a colon after the else.

// If you are looking for John to be entered
print("Enter your name user:")
if input() == "John":
   print("Hi John")
else: 
   print("You are not John!")
how i do css
posted to Ask by GAKiaraM

It's a big topic. You will need to find some good tutorials. Here are a few links:
https://www.w3schools.com/Css/default.asp
https://www.youtube.com/watch?v=yfoY53QXEnI

Exponential Function Calculator
posted to Share by YashKanda

Here is something more concise and flexible:

base = float(input("What is the base of the exponential function: "))
lower_power_limit = int(input("What is the lowest power you want to use: "))
upper_power_limit = int(input("What is the highest power you want to use: "))

step = 1

for power in range(lower_power_limit, upper_power_limit + 1, step):
  print(base, "to the power of", power, "is", pow(base, power))
I want to switch my technical support job to Data Scientist or Python developer ??
posted to Ask by amar969

Find a job before resigning from your current one!

How can i define the tangent function?
posted to Ask by Thatoneguy130

tan(angle) = sin(angle) / cos(angle)
What language are you wanting to use to graph the function?

How do I run my second file?
posted to Ask by AndresHaro1

You will need to import the code in string_basics into the main.py file. You can do it like so:

import string_basics
print(string_basics.sentence)
print(string_basics.sentence_two)
...and so on

Note that you need to prefix the sentence name with the name of the module. To geta round this you could use a different import syntax, like so:

from string_basics import *
print(sentence)
print(sentence_two)
...and so on

The import statement can be read as "from the string_basics module import all"

What's wrong with my code
posted to Ask by GalaxyWolfX

You need to have a Main.java file that contains just the Main class. Create your other classes in separate files and use them in Main like so: https://repl.it/@malvoliothegood/java-example

Parse Error: bad input (but I'm not sure what the issue is)
posted to Ask by MatthewRodrigu2

I get an error on line 606 when I run your program. It is because the code within the draw_hill function is not indented. You are also defining the draw_curve function within the draw_canyon one. This looks a bit suspect to me.

JS Assignment 16: Using Callbacks in Array Methods
posted to Ask by maximussallam

Study these examples: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
And:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
Note that the map example can be written:

var array1 = [1, 4, 9, 16];

// This function doubles the input value and returns it
function doubler(x) {
    return x * 2;
}
// pass the function to map
const map1 = array1.map(doubler);

console.log(map1);
// expected output: Array [2, 8, 18, 32]
Can someone pls explain this code?
posted to Ask by ZestyLad

Lets track the value of variables when the nt_to_Roman function is called with the input value of 16.
1. The num variable is assigned the value 16
2. The two variables val and syb are declared and initialised along with roman_num and i.
3. The while loop is entered and as num is greater than 0 the body of the while is entered.
4. The expression num // val[i] is evaluated. The // operator is gives an integer division. This means that 4 // 2 => 2, and 5 // 2 is also 2 as the 0.5 remainder is discarded. First time through the loop num // val[i] evaluates to 16 // val[0] => 16 // 1000 => 0. This means the code in the for loop will repeat 0 times.
5. Next the value of i (currently at 0) will be increased by 1 so it's value is 1
6. The code execution will then move back to the top of the loop and num will be compared with 0 and as it is greater execution will pass to the next line of code and num // val[i] will be evaluated. As i is 1 val[i] will be 900 and the expression will be 16 // 900. This gives 0 again, so the for loop will not run and i will increase by 1.
7. Code execution proceeds in this way until 16 // val[i] gives a none zero result. This happens when i is 8 and val[i] is 10 and the expression is 16 // 10 => 1 (remember that the remainder is discarded. Now range(num // val[i]) becomes range(1) meaning the code within the for loop will execute once.
8. roman_num += syb[i] => roman_num += 'X', meaning roman_num chnages from an empty string to X.
9. num -= val[i] => num = num - val[i] => num = 16 - 10 => num = 6
10. i is then increased by 1 and becomes 2
11. Code execution jumps back to the top of the loop and num (value of 6) is tested to see that it is greater than 0. It is.
12. The for loop is then entered. num // val[i] => 6 // 9 => 0. So the for loop does not execute. num // val[i] will be greater than 0 when i is 10 and val[i] is 5.
13. When the for loop code does execute (once): roman_num += syb[i] => roman_num = roman_num + syb[i] => roman_num = 'X' + 'V' => roman_num = 'XV'.
14. By now you have probably seen the code execution pattern.

I have forked your program and edited the code so a class is not used (it's not needed) and a range of numbers is converted to Roman Numerals: https://repl.it/@malvoliothegood/Roman-Numeral-Converter

**FOR LOOPS IN PYTHON**
posted to Ask by bhavika29

Here is some examples. There are some reference links at the top of the code for you to follow up: https://repl.it/@malvoliothegood/loops

PHP and MySQLi
posted to Ask by Lightcaster5

@Lightcaster5 I think I understood what you meant. My answer said I don't think you can do this and I included a link to an old conversation that basically said this. If you find an answer that lets you do such a hook up let me know. All the best.

Python indentation errors.
posted to Ask

There is a hidden indentation issue to do with the "direction = input(..... " line of code. Your "ifs" are too far indented as well. What you need to do is highlight all the code in the movement function then hold down the shift key and press the tab key. This will unindent the code by one tab. Repeat this until "direction = input(... " and the "if" blocks of code are touching the left hand edge. The code should still be highlighted (as long as you have not clicked away from it). Now press just the tab key once. The code should now be correctly indented.

Your code could be more efficient. After the first "if" use "elif"s instead of the repeated "if"s, apart from the last "if" which could be an "else" as it is the last possible choice.

There are one or two other things you could do to improve your code. For instance, how can the user break out of the movement function as it is always called?

C++ spaces in string input
posted to Ask by SilentShadowBla

It should work. This works for me:

#include <iostream>

using namespace std;

int main() {
  string message;
  cout << "Type your message: ";
  getline(cin, message);
  cout << messageVar;

  cout << "\nType your message again: ";
  getline(cin, message);
  cout << message;
}

Where is the rest of your code? Provide a link to your repl.

when - print (colors) the output comes ['Green', 'Black', 'Blue']
posted to Ask by yamit1918

You can make your own function that prints a list as you see fit. The code below prints the items in a list separated by a comma and space:

def print_list(a_list):
  str = ''
  for item in a_list:
    str += item + ', '
  # Remove last comma and space from the end
  # of the string as it's not needed
  print(str[:-2])


colors = ["Green", "Red", "Blue"] # Do not modify this line
# Insert your code below this line
# Print "Green" by using it's index
print (colors[0] )
# Print "Blue" by using it's index
print (colors[2])
# Add "Black" to the second index
colors[1] = "Black"
# Print the updated colors list
print_list (colors)
# Append "Orange" to the colors list
colors.append("Orange") 
# Print the updated colors list
print_list(colors)
How to display the fetched image array?
posted to Ask by PhilipChristian

Cool little program. You don't have to use jQuery these days. I forked your program and edited the code. See what you think: https://repl.it/@malvoliothegood/1-to-50-Random-Dog-API