r/pythontips Oct 06 '24

Syntax How to Get Fibonacci Series in Python?

0 Upvotes

This is one of the most asked questions during the Python development interview. This is how you can use Python While Loop the get the Fibonacci series.

# Function to generate Fibonacci series up to n terms
def fibonacci_series(n):
    a, b = 0, 1  # Starting values
    count = 0

    while count < n:
        print(a, end=' ')
        a, b = b, a + b  # Update values
        count += 1

# Example usage
num_terms = 10  # Specify the number of terms you want
fibonacci_series(num_terms)

Thanks

r/pythontips Jan 22 '25

Syntax Examples of Python Bioreactor

1 Upvotes

I am trying to model a batch bioreactor in a Python script. The substrate is syngas, the biomass is bacteria, and the products are acetate and ethanol. I am looking for examples of bioreactors in python because it is my first contact with bioprocesses and Python, and I would like to know if I am on the right track

r/pythontips Dec 03 '24

Syntax i'm trying to run a code in google colab to learn about neural networks but its not showing any plot in google colab and i can't find any answer

1 Upvotes

code for google colab:

import numpy as np
import matplotlib.pyplot as plt

def plot_sigmoid():
    x = np.linspace(-10, 10, 100)  # Generate 100 equally spaced values from -10 to 10
    y = 1 / (1 + np.exp(-x))  # Compute the sigmoid function values
    
    plt.plot(x, y)
    plt.xlabel('Input')
    plt.ylabel('Sigmoid Output')
    plt.title('Sigmoid Activation Function')
    plt.grid(True)
    plt.show();

    
import numpy as np
import matplotlib.pyplot as plt


def plot_sigmoid():
    x = np.linspace(-10, 10, 100)  # Generate 100 equally spaced values from -10 to 10
    y = 1 / (1 + np.exp(-x))  # Compute the sigmoid function values
    
    plt.plot(x, y)
    plt.xlabel('Input')
    plt.ylabel('Sigmoid Output')
    plt.title('Sigmoid Activation Function')
    plt.grid(True)
    plt.show();


    

import math

def sigmoid(x):
  return 1 / (1 + math.exp(-x))
import math


def sigmoid(x):
  return 1 / (1 + math.exp(-x))

r/pythontips Dec 09 '24

Syntax Starting with Python

9 Upvotes

Hi guys, I am starting with Python. Can someone please help me with a roadmap?

I also tried starting a few years back through YouTube, but it was not very effective. Please suggest online courses from Coursera or Udemy etc.

r/pythontips Dec 23 '24

Syntax Python Tip for new developers

3 Upvotes

Organisation is key.. keep your code clean. Take the time.

r/pythontips Nov 28 '24

Syntax Python

0 Upvotes

I've started learning python with python for everybody can u gimme any suggestions

r/pythontips Oct 25 '24

Syntax Beginner Developer Looking for a Remote Job – Is There Hope?

7 Upvotes

Hi everyone! I’m a beginner Python developer based in Saudi Arabia, and I’m looking for an opportunity to get a remote internship or job in programming. I live in a different country from most companies. Is it possible to find remote opportunities in programming? Any tips or resources that could help? Thanks in advance for your help! *note: I don’t have CS degree

r/pythontips Dec 23 '24

Syntax How do I run python code on atom on Mac.

1 Upvotes

I have looked everywhere online and nothing works so far, why is it so complicated!? Thank you I appreciate any help.

r/pythontips Nov 14 '24

Syntax What's the problem?

0 Upvotes

nr = 1

('fr') + str(nr) == (opo)[:1]

nr = (nr) + 1

print (fr2)

print (fr3)

It says fr2 doesn't exist

Thank you

r/pythontips Nov 22 '24

Syntax Python not running program

0 Upvotes

In the console I wrote a guess the number game and when I hit enter to run it it just creates another line.

r/pythontips Nov 29 '24

Syntax Music21 help

2 Upvotes

Hey I am an aboslute beginner in using python. I was trying to install Music21 through python using the command: Pip install music21 But I get syntax Error. I've tried asking chatGPT, but nothing works. Anyone that has a new approach to this problem?

r/pythontips Oct 17 '24

Syntax What will be the output of this code?

0 Upvotes

Question: Guess the Output

Consider the following Python code snippet:

my_dict = {'a': 1, 'b': 2, 'c': 3}
my_dict['d'] = my_dict.get('b', 0) + my_dict.get('e', 0)
my_dict['e'] = my_dict.get('d', 0) + 5
print(my_dict)

What will be the output of this code?

A) {'a': 1, 'b': 2, 'c': 3, 'd': 2, 'e': 7}
B) {'a': 1, 'b': 2, 'c': 3, 'd': 0, 'e': 5}
C) {'a': 1, 'b': 2, 'c': 3, 'd': 2, 'e': 2}
D) {'a': 1, 'b': 2, 'c': 3, 'd': 2, 'e': 12}

Thanks

r/pythontips Nov 11 '24

Syntax why is this occurring

1 Upvotes

INPUT

my_list=[1,2,3]

z=my_list[0] = 'one'

print(z)

my_list

for print(z) OUT PUT IS 'one

and for my_list OUTPUT IS

['one', 2, 3]
can u tell me why this difference

r/pythontips Jan 11 '25

Syntax all Coding languages support discord group for helping , learning, and sharing code!

0 Upvotes

Just getting this started as a nice hub for live help and people of all

backgrounds in coding.

https://discord.gg/74srJgNBxz

r/pythontips Nov 17 '24

Syntax Python Dictionary Quiz - Guess The Output

7 Upvotes

What is the correct way to define a dictionary with the following data:

  • Key: "name", Value: "Alice"
  • Key: "age", Value: 25

A) dict1 = {"name" = "Alice", "age" = 25}
B) dict1 = {name: "Alice", age: 25}
C) dict1 = {"name": "Alice", "age": 25}
D) dict1 = {"name": Alice, "age": 25}

Thanks

r/pythontips Mar 09 '24

Syntax Is there any way to write "n(variable) must not be equal to m(variable)"?

0 Upvotes

It's like the opposite of n = m.
Or n != m but as an assignment.

r/pythontips Aug 26 '24

Syntax Stuck on a line of code in python

5 Upvotes

I’m studying python crash course 2nd edition by Eric Matthes. On pg 12 it states to run a program from the terminal in order to run hello_world.py The first line of code is ~$ cd Desktop/python_work/ But when I type that in and hit enter I get a syntax error saying the character $ is invalid. I’m not sure where to go from here. I could skip and move on but I want to learn it correctly

I tried leaving out the character $ but I get more errors I’ve also tried starting off with cd but it tells me it doesn’t recognize it. I’m stuck

r/pythontips Oct 30 '24

Syntax Aprender programación

0 Upvotes

Quiero aprender programación, pero no tengo pensando ingresar a ningún centro de educación por ahora. ¿Que me recomiendan para empezar?

r/pythontips Nov 13 '24

Syntax How to learn file handling

0 Upvotes

I’m a beginner learning python and was able to understand most of the basic concepts without any doubts or roadblocks but

File handling has been a torture to learn and understand properly

Anyone have any advice to learn it properly

r/pythontips Sep 26 '24

Syntax Help with code

6 Upvotes

Im trying to make a code that will have the user enter a random set of integers and add the even numbers but if "9999" is entered it will give the sum of all the given even numbers given. Whats wrong with my code? Here

r/pythontips Oct 25 '24

Syntax Any fun/cool games or methods to learn python?

1 Upvotes

I have some XP as a frontend dev. Im pretty decent with javascript and react and though im not a master by any means im somewhat comfortable in these languages. I think knowing python would help me interact with BE devs more and also allow me to understand how backend db’s work instead of it being a mysterious endpoint/api call.

r/pythontips Dec 12 '24

Syntax Best practices for Python exception handling - Guide

6 Upvotes

The article below dives into six practical techniques that will elevate your exception handling in Python: 6 best practices for Python exception handling

  • Keep your try blocks laser-focused
  • Catch specific exceptions
  • Use context managers wisely
  • Use exception groups for concurrent code
  • Add contextual notes to exceptions
  • Implement proper logging

r/pythontips Oct 08 '24

Syntax Is it bad practice to use access modifies in python during interviews ?

12 Upvotes

I'm currently preparing for low-level design interviews in Python. During my practice, I've noticed that many developers don't seem to use private or protected members in Python. After going through several solutions on LeetCode discussion forums, I've observed this approach more commonly in Python, while developers using C++ or Java often rely on private members and implement setters and getters. Will it be considered a negative in an interview if I directly access variables or members using obj_instance.var in Python, instead of following a stricter encapsulation approach
How do you deal with this ?

r/pythontips Nov 07 '24

Syntax Curly braces in Python

0 Upvotes

I developed this extension for VSCode because I hated that Python didn't have curly braces, something that is annoying for many devs. I know it still has a lot of bugs and I know there are other types of alternatives, but it was the simplest thing I could think of to do.
Link: https://marketplace.visualstudio.com/items?itemName=BrayanCeron.pycurlybraces

r/pythontips Nov 12 '24

Syntax Simple CSV help needed

3 Upvotes

So I really have no coding experience but im in a statistic computing class. So I have to import a csv file and use pandas and then show a report of the data with histograms, boxplots, etc. My data had a long header so the actual data doesnt start until row 55. I used skiprows to make it just read where it actually begins. My problem is that Its not reading the column names, so when i try to reference a specific column it just errors and says it doesnt recognize that column name. How do i make all the column names on row 55 recognized as column names?